blob: 6c010463b9dba6b20ca16f167e9503d92ffb5daf [file] [log] [blame]
Chris Masone20d96d2007-03-22 12:13:20 -04001#include <linux/module.h>
2#include <linux/fs.h>
Chris Masond98237b2007-03-28 13:57:48 -04003#include <linux/blkdev.h>
Chris Mason87cbda52007-03-28 19:44:27 -04004#include <linux/crypto.h>
5#include <linux/scatterlist.h>
Chris Mason22b0ebd2007-03-30 08:47:31 -04006#include <linux/swap.h>
Chris Masoneb60cea2007-02-02 09:18:22 -05007#include "ctree.h"
8#include "disk-io.h"
Chris Masone089f052007-03-16 16:20:31 -04009#include "transaction.h"
Chris Masoneb60cea2007-02-02 09:18:22 -050010
Chris Masond98237b2007-03-28 13:57:48 -040011
Chris Masone20d96d2007-03-22 12:13:20 -040012static int check_tree_block(struct btrfs_root *root, struct buffer_head *buf)
Chris Masoneb60cea2007-02-02 09:18:22 -050013{
Chris Masone20d96d2007-03-22 12:13:20 -040014 struct btrfs_node *node = btrfs_buffer_node(buf);
Chris Masond98237b2007-03-28 13:57:48 -040015 if (buf->b_blocknr != btrfs_header_blocknr(&node->header)) {
Chris Mason9a8dd152007-02-23 08:38:36 -050016 BUG();
Chris Masond98237b2007-03-28 13:57:48 -040017 }
Chris Masone20d96d2007-03-22 12:13:20 -040018 if (root->node && btrfs_header_parentid(&node->header) !=
Chris Masondf2ce342007-03-23 11:00:45 -040019 btrfs_header_parentid(btrfs_buffer_header(root->node))) {
Chris Mason7f5c1512007-03-23 15:56:19 -040020 BUG();
Chris Masondf2ce342007-03-23 11:00:45 -040021 }
Chris Mason9a8dd152007-02-23 08:38:36 -050022 return 0;
Chris Masoneb60cea2007-02-02 09:18:22 -050023}
24
Chris Masond98237b2007-03-28 13:57:48 -040025struct buffer_head *btrfs_find_tree_block(struct btrfs_root *root, u64 blocknr)
Chris Masoned2ff2c2007-03-01 18:59:40 -050026{
Chris Masond98237b2007-03-28 13:57:48 -040027 struct address_space *mapping = root->fs_info->btree_inode->i_mapping;
28 int blockbits = root->fs_info->sb->s_blocksize_bits;
29 unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits);
30 struct page *page;
31 struct buffer_head *bh;
32 struct buffer_head *head;
33 struct buffer_head *ret = NULL;
34
35 page = find_lock_page(mapping, index);
36 if (!page)
37 return NULL;
38
39 if (!page_has_buffers(page))
40 goto out_unlock;
41
42 head = page_buffers(page);
43 bh = head;
44 do {
45 if (buffer_mapped(bh) && bh->b_blocknr == blocknr) {
46 ret = bh;
47 get_bh(bh);
48 goto out_unlock;
49 }
50 bh = bh->b_this_page;
51 } while (bh != head);
52out_unlock:
53 unlock_page(page);
Chris Mason22b0ebd2007-03-30 08:47:31 -040054 if (ret)
55 touch_buffer(ret);
Chris Masond98237b2007-03-28 13:57:48 -040056 page_cache_release(page);
57 return ret;
Chris Masoned2ff2c2007-03-01 18:59:40 -050058}
59
Chris Masond98237b2007-03-28 13:57:48 -040060struct buffer_head *btrfs_find_create_tree_block(struct btrfs_root *root,
61 u64 blocknr)
Chris Masoneb60cea2007-02-02 09:18:22 -050062{
Chris Masond98237b2007-03-28 13:57:48 -040063 struct address_space *mapping = root->fs_info->btree_inode->i_mapping;
64 int blockbits = root->fs_info->sb->s_blocksize_bits;
65 unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits);
66 struct page *page;
67 struct buffer_head *bh;
68 struct buffer_head *head;
69 struct buffer_head *ret = NULL;
70 u64 first_block = index << (PAGE_CACHE_SHIFT - blockbits);
Chris Mason22b0ebd2007-03-30 08:47:31 -040071
Chris Masond98237b2007-03-28 13:57:48 -040072 page = grab_cache_page(mapping, index);
73 if (!page)
74 return NULL;
75
Chris Masond98237b2007-03-28 13:57:48 -040076 if (!page_has_buffers(page))
77 create_empty_buffers(page, root->fs_info->sb->s_blocksize, 0);
78 head = page_buffers(page);
79 bh = head;
80 do {
81 if (!buffer_mapped(bh)) {
82 bh->b_bdev = root->fs_info->sb->s_bdev;
83 bh->b_blocknr = first_block;
84 set_buffer_mapped(bh);
85 }
86 if (bh->b_blocknr == blocknr) {
87 ret = bh;
88 get_bh(bh);
89 goto out_unlock;
90 }
91 bh = bh->b_this_page;
92 first_block++;
93 } while (bh != head);
94out_unlock:
95 unlock_page(page);
Chris Mason22b0ebd2007-03-30 08:47:31 -040096 if (ret)
97 touch_buffer(ret);
Chris Masond98237b2007-03-28 13:57:48 -040098 page_cache_release(page);
99 return ret;
Chris Masone20d96d2007-03-22 12:13:20 -0400100}
Chris Mason123abc82007-03-14 14:14:43 -0400101
Chris Masond98237b2007-03-28 13:57:48 -0400102static sector_t max_block(struct block_device *bdev)
103{
104 sector_t retval = ~((sector_t)0);
105 loff_t sz = i_size_read(bdev->bd_inode);
106
107 if (sz) {
108 unsigned int size = block_size(bdev);
109 unsigned int sizebits = blksize_bits(size);
110 retval = (sz >> sizebits);
111 }
112 return retval;
113}
114
115static int btree_get_block(struct inode *inode, sector_t iblock,
116 struct buffer_head *bh, int create)
117{
118 if (iblock >= max_block(inode->i_sb->s_bdev)) {
119 if (create)
120 return -EIO;
121
122 /*
123 * for reads, we're just trying to fill a partial page.
124 * return a hole, they will have to call get_block again
125 * before they can fill it, and they will get -EIO at that
126 * time
127 */
128 return 0;
129 }
130 bh->b_bdev = inode->i_sb->s_bdev;
131 bh->b_blocknr = iblock;
132 set_buffer_mapped(bh);
133 return 0;
134}
135
Chris Masonf254e522007-03-29 15:15:27 -0400136int btrfs_csum_data(struct btrfs_root * root, char *data, size_t len,
137 char *result)
Chris Mason87cbda52007-03-28 19:44:27 -0400138{
Chris Mason87cbda52007-03-28 19:44:27 -0400139 struct scatterlist sg;
140 struct crypto_hash *tfm = root->fs_info->hash_tfm;
141 struct hash_desc desc;
142 int ret;
Chris Mason87cbda52007-03-28 19:44:27 -0400143
144 desc.tfm = tfm;
145 desc.flags = 0;
Chris Masonf254e522007-03-29 15:15:27 -0400146 sg_init_one(&sg, data, len);
Chris Mason87cbda52007-03-28 19:44:27 -0400147 spin_lock(&root->fs_info->hash_lock);
Chris Mason22b0ebd2007-03-30 08:47:31 -0400148 ret = crypto_hash_digest(&desc, &sg, 1, result);
Chris Mason87cbda52007-03-28 19:44:27 -0400149 spin_unlock(&root->fs_info->hash_lock);
150 if (ret) {
151 printk("sha256 digest failed\n");
152 }
Chris Masonf254e522007-03-29 15:15:27 -0400153 return ret;
154}
155static int csum_tree_block(struct btrfs_root *root, struct buffer_head *bh,
156 int verify)
157{
158 char result[BTRFS_CSUM_SIZE];
159 int ret;
160 struct btrfs_node *node;
161
Chris Mason22b0ebd2007-03-30 08:47:31 -0400162 return 0;
Chris Masonf254e522007-03-29 15:15:27 -0400163 ret = btrfs_csum_data(root, bh->b_data + BTRFS_CSUM_SIZE,
164 bh->b_size - BTRFS_CSUM_SIZE, result);
165 if (ret)
166 return ret;
Chris Mason87cbda52007-03-28 19:44:27 -0400167 if (verify) {
Chris Masonf254e522007-03-29 15:15:27 -0400168 if (memcmp(bh->b_data, result, BTRFS_CSUM_SIZE)) {
169 printk("checksum verify failed on %lu\n",
170 bh->b_blocknr);
171 return 1;
172 }
173 } else {
174 node = btrfs_buffer_node(bh);
Chris Mason22b0ebd2007-03-30 08:47:31 -0400175 memcpy(node->header.csum, result, BTRFS_CSUM_SIZE);
Chris Masonf254e522007-03-29 15:15:27 -0400176 }
Chris Mason87cbda52007-03-28 19:44:27 -0400177 return 0;
178}
179
Chris Masond98237b2007-03-28 13:57:48 -0400180static int btree_writepage(struct page *page, struct writeback_control *wbc)
181{
Chris Mason22b0ebd2007-03-30 08:47:31 -0400182#if 0
Chris Mason87cbda52007-03-28 19:44:27 -0400183 struct buffer_head *bh;
184 struct btrfs_root *root = btrfs_sb(page->mapping->host->i_sb);
185 struct buffer_head *head;
Chris Mason87cbda52007-03-28 19:44:27 -0400186 if (!page_has_buffers(page)) {
187 create_empty_buffers(page, root->fs_info->sb->s_blocksize,
188 (1 << BH_Dirty)|(1 << BH_Uptodate));
189 }
190 head = page_buffers(page);
191 bh = head;
192 do {
193 if (buffer_dirty(bh))
194 csum_tree_block(root, bh, 0);
195 bh = bh->b_this_page;
196 } while (bh != head);
Chris Mason22b0ebd2007-03-30 08:47:31 -0400197#endif
Chris Masond98237b2007-03-28 13:57:48 -0400198 return block_write_full_page(page, btree_get_block, wbc);
199}
200
201static int btree_readpage(struct file * file, struct page * page)
202{
203 return block_read_full_page(page, btree_get_block);
204}
205
206static struct address_space_operations btree_aops = {
207 .readpage = btree_readpage,
208 .writepage = btree_writepage,
209 .sync_page = block_sync_page,
210};
211
Chris Masone20d96d2007-03-22 12:13:20 -0400212struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr)
213{
Chris Masond98237b2007-03-28 13:57:48 -0400214 struct buffer_head *bh = NULL;
Chris Masone20d96d2007-03-22 12:13:20 -0400215
Chris Masond98237b2007-03-28 13:57:48 -0400216 bh = btrfs_find_create_tree_block(root, blocknr);
217 if (!bh)
218 return bh;
219 lock_buffer(bh);
220 if (!buffer_uptodate(bh)) {
221 get_bh(bh);
222 bh->b_end_io = end_buffer_read_sync;
223 submit_bh(READ, bh);
224 wait_on_buffer(bh);
225 if (!buffer_uptodate(bh))
226 goto fail;
Chris Mason87cbda52007-03-28 19:44:27 -0400227 csum_tree_block(root, bh, 1);
Chris Masond98237b2007-03-28 13:57:48 -0400228 } else {
229 unlock_buffer(bh);
230 }
231 if (check_tree_block(root, bh))
Chris Masoncfaa7292007-02-21 17:04:57 -0500232 BUG();
Chris Masond98237b2007-03-28 13:57:48 -0400233 return bh;
234fail:
235 brelse(bh);
236 return NULL;
237
Chris Masoneb60cea2007-02-02 09:18:22 -0500238}
239
Chris Masone089f052007-03-16 16:20:31 -0400240int dirty_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
Chris Masone20d96d2007-03-22 12:13:20 -0400241 struct buffer_head *buf)
Chris Masoned2ff2c2007-03-01 18:59:40 -0500242{
Chris Masone20d96d2007-03-22 12:13:20 -0400243 mark_buffer_dirty(buf);
Chris Masoned2ff2c2007-03-01 18:59:40 -0500244 return 0;
245}
246
Chris Masone089f052007-03-16 16:20:31 -0400247int clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
Chris Masone20d96d2007-03-22 12:13:20 -0400248 struct buffer_head *buf)
Chris Masoned2ff2c2007-03-01 18:59:40 -0500249{
Chris Masone20d96d2007-03-22 12:13:20 -0400250 clear_buffer_dirty(buf);
Chris Masoned2ff2c2007-03-01 18:59:40 -0500251 return 0;
252}
253
Chris Mason123abc82007-03-14 14:14:43 -0400254static int __setup_root(struct btrfs_super_block *super,
Chris Mason9f5fae22007-03-20 14:38:32 -0400255 struct btrfs_root *root,
256 struct btrfs_fs_info *fs_info,
Chris Masone20d96d2007-03-22 12:13:20 -0400257 u64 objectid)
Chris Masond97e63b2007-02-20 16:40:44 -0500258{
Chris Masoncfaa7292007-02-21 17:04:57 -0500259 root->node = NULL;
Chris Masona28ec192007-03-06 20:08:01 -0500260 root->commit_root = NULL;
Chris Mason123abc82007-03-14 14:14:43 -0400261 root->blocksize = btrfs_super_blocksize(super);
262 root->ref_cows = 0;
Chris Mason9f5fae22007-03-20 14:38:32 -0400263 root->fs_info = fs_info;
Chris Mason3768f362007-03-13 16:47:54 -0400264 memset(&root->root_key, 0, sizeof(root->root_key));
265 memset(&root->root_item, 0, sizeof(root->root_item));
266 return 0;
267}
268
Chris Mason123abc82007-03-14 14:14:43 -0400269static int find_and_setup_root(struct btrfs_super_block *super,
Chris Mason9f5fae22007-03-20 14:38:32 -0400270 struct btrfs_root *tree_root,
271 struct btrfs_fs_info *fs_info,
272 u64 objectid,
Chris Masone20d96d2007-03-22 12:13:20 -0400273 struct btrfs_root *root)
Chris Mason3768f362007-03-13 16:47:54 -0400274{
275 int ret;
276
Chris Masone20d96d2007-03-22 12:13:20 -0400277 __setup_root(super, root, fs_info, objectid);
Chris Mason3768f362007-03-13 16:47:54 -0400278 ret = btrfs_find_last_root(tree_root, objectid,
279 &root->root_item, &root->root_key);
280 BUG_ON(ret);
281
282 root->node = read_tree_block(root,
283 btrfs_root_blocknr(&root->root_item));
Chris Mason3768f362007-03-13 16:47:54 -0400284 BUG_ON(!root->node);
Chris Masond97e63b2007-02-20 16:40:44 -0500285 return 0;
286}
287
Chris Masone20d96d2007-03-22 12:13:20 -0400288struct btrfs_root *open_ctree(struct super_block *sb,
289 struct buffer_head *sb_buffer,
290 struct btrfs_super_block *disk_super)
Chris Masoneb60cea2007-02-02 09:18:22 -0500291{
Chris Masone20d96d2007-03-22 12:13:20 -0400292 struct btrfs_root *root = kmalloc(sizeof(struct btrfs_root),
293 GFP_NOFS);
294 struct btrfs_root *extent_root = kmalloc(sizeof(struct btrfs_root),
295 GFP_NOFS);
296 struct btrfs_root *tree_root = kmalloc(sizeof(struct btrfs_root),
297 GFP_NOFS);
298 struct btrfs_root *inode_root = kmalloc(sizeof(struct btrfs_root),
299 GFP_NOFS);
300 struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info),
301 GFP_NOFS);
Chris Masoneb60cea2007-02-02 09:18:22 -0500302 int ret;
303
Chris Mason87cbda52007-03-28 19:44:27 -0400304 if (!btrfs_super_root(disk_super)) {
Chris Masone20d96d2007-03-22 12:13:20 -0400305 return NULL;
Chris Mason87cbda52007-03-28 19:44:27 -0400306 }
Chris Mason8ef97622007-03-26 10:15:30 -0400307 init_bit_radix(&fs_info->pinned_radix);
308 init_bit_radix(&fs_info->pending_del_radix);
Chris Masond98237b2007-03-28 13:57:48 -0400309 sb_set_blocksize(sb, sb_buffer->b_size);
Chris Mason9f5fae22007-03-20 14:38:32 -0400310 fs_info->running_transaction = NULL;
311 fs_info->fs_root = root;
312 fs_info->tree_root = tree_root;
313 fs_info->extent_root = extent_root;
314 fs_info->inode_root = inode_root;
315 fs_info->last_inode_alloc = 0;
316 fs_info->last_inode_alloc_dirid = 0;
Chris Masone20d96d2007-03-22 12:13:20 -0400317 fs_info->disk_super = disk_super;
Chris Masone20d96d2007-03-22 12:13:20 -0400318 fs_info->sb = sb;
Chris Masond98237b2007-03-28 13:57:48 -0400319 fs_info->btree_inode = new_inode(sb);
320 fs_info->btree_inode->i_ino = 1;
321 fs_info->btree_inode->i_size = sb->s_bdev->bd_inode->i_size;
322 fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
Chris Mason22b0ebd2007-03-30 08:47:31 -0400323 insert_inode_hash(fs_info->btree_inode);
324
Chris Masond98237b2007-03-28 13:57:48 -0400325 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
Chris Mason87cbda52007-03-28 19:44:27 -0400326 fs_info->hash_tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
Chris Mason30ae8462007-03-29 09:59:15 -0400327 spin_lock_init(&fs_info->hash_lock);
328
329 if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) {
Chris Mason87cbda52007-03-28 19:44:27 -0400330 printk("failed to allocate sha256 hash\n");
331 return NULL;
332 }
Chris Masond98237b2007-03-28 13:57:48 -0400333
Chris Mason79154b12007-03-22 15:59:16 -0400334 mutex_init(&fs_info->trans_mutex);
Chris Masond561c022007-03-23 19:47:49 -0400335 mutex_init(&fs_info->fs_mutex);
Chris Mason9f5fae22007-03-20 14:38:32 -0400336 memset(&fs_info->current_insert, 0, sizeof(fs_info->current_insert));
337 memset(&fs_info->last_insert, 0, sizeof(fs_info->last_insert));
Chris Mason3768f362007-03-13 16:47:54 -0400338
Chris Masone20d96d2007-03-22 12:13:20 -0400339 __setup_root(disk_super, tree_root, fs_info, BTRFS_ROOT_TREE_OBJECTID);
Chris Masond98237b2007-03-28 13:57:48 -0400340
341 fs_info->sb_buffer = read_tree_block(tree_root, sb_buffer->b_blocknr);
342
Chris Mason87cbda52007-03-28 19:44:27 -0400343 if (!fs_info->sb_buffer) {
344printk("failed2\n");
Chris Masond98237b2007-03-28 13:57:48 -0400345 return NULL;
Chris Mason87cbda52007-03-28 19:44:27 -0400346 }
Chris Masond98237b2007-03-28 13:57:48 -0400347 brelse(sb_buffer);
348 sb_buffer = NULL;
349 disk_super = (struct btrfs_super_block *)fs_info->sb_buffer->b_data;
350 fs_info->disk_super = disk_super;
351
Chris Masone20d96d2007-03-22 12:13:20 -0400352 tree_root->node = read_tree_block(tree_root,
353 btrfs_super_root(disk_super));
Chris Mason3768f362007-03-13 16:47:54 -0400354 BUG_ON(!tree_root->node);
355
Chris Masone20d96d2007-03-22 12:13:20 -0400356 ret = find_and_setup_root(disk_super, tree_root, fs_info,
357 BTRFS_EXTENT_TREE_OBJECTID, extent_root);
Chris Mason3768f362007-03-13 16:47:54 -0400358 BUG_ON(ret);
359
Chris Masone20d96d2007-03-22 12:13:20 -0400360 ret = find_and_setup_root(disk_super, tree_root, fs_info,
361 BTRFS_INODE_MAP_OBJECTID, inode_root);
Chris Mason9f5fae22007-03-20 14:38:32 -0400362 BUG_ON(ret);
363
Chris Masone20d96d2007-03-22 12:13:20 -0400364 ret = find_and_setup_root(disk_super, tree_root, fs_info,
365 BTRFS_FS_TREE_OBJECTID, root);
Chris Mason3768f362007-03-13 16:47:54 -0400366 BUG_ON(ret);
Chris Masona28ec192007-03-06 20:08:01 -0500367 root->commit_root = root->node;
Chris Masone20d96d2007-03-22 12:13:20 -0400368 get_bh(root->node);
Chris Mason3768f362007-03-13 16:47:54 -0400369 root->ref_cows = 1;
Chris Mason293ffd52007-03-20 15:57:25 -0400370 root->fs_info->generation = root->root_key.offset + 1;
Chris Masoneb60cea2007-02-02 09:18:22 -0500371 return root;
372}
373
Chris Masone089f052007-03-16 16:20:31 -0400374int write_ctree_super(struct btrfs_trans_handle *trans, struct btrfs_root
Chris Mason79154b12007-03-22 15:59:16 -0400375 *root)
Chris Masoncfaa7292007-02-21 17:04:57 -0500376{
Chris Masond5719762007-03-23 10:01:08 -0400377 struct buffer_head *bh = root->fs_info->sb_buffer;
378 btrfs_set_super_root(root->fs_info->disk_super,
379 root->fs_info->tree_root->node->b_blocknr);
380 lock_buffer(bh);
381 clear_buffer_dirty(bh);
Chris Mason87cbda52007-03-28 19:44:27 -0400382 csum_tree_block(root, bh, 0);
Chris Masond5719762007-03-23 10:01:08 -0400383 bh->b_end_io = end_buffer_write_sync;
384 get_bh(bh);
385 submit_bh(WRITE, bh);
386 wait_on_buffer(bh);
387 if (!buffer_uptodate(bh)) {
388 WARN_ON(1);
389 return -EIO;
Chris Masoncfaa7292007-02-21 17:04:57 -0500390 }
391 return 0;
392}
393
Chris Masone20d96d2007-03-22 12:13:20 -0400394int close_ctree(struct btrfs_root *root)
Chris Masoneb60cea2007-02-02 09:18:22 -0500395{
Chris Mason3768f362007-03-13 16:47:54 -0400396 int ret;
Chris Masone089f052007-03-16 16:20:31 -0400397 struct btrfs_trans_handle *trans;
398
Chris Mason79154b12007-03-22 15:59:16 -0400399 trans = btrfs_start_transaction(root, 1);
400 btrfs_commit_transaction(trans, root);
401 /* run commit again to drop the original snapshot */
402 trans = btrfs_start_transaction(root, 1);
403 btrfs_commit_transaction(trans, root);
404 ret = btrfs_write_and_wait_transaction(NULL, root);
Chris Mason9f5fae22007-03-20 14:38:32 -0400405 BUG_ON(ret);
Chris Mason79154b12007-03-22 15:59:16 -0400406 write_ctree_super(NULL, root);
Chris Masoned2ff2c2007-03-01 18:59:40 -0500407
Chris Masoneb60cea2007-02-02 09:18:22 -0500408 if (root->node)
Chris Mason234b63a2007-03-13 10:46:10 -0400409 btrfs_block_release(root, root->node);
Chris Mason9f5fae22007-03-20 14:38:32 -0400410 if (root->fs_info->extent_root->node)
411 btrfs_block_release(root->fs_info->extent_root,
412 root->fs_info->extent_root->node);
413 if (root->fs_info->inode_root->node)
414 btrfs_block_release(root->fs_info->inode_root,
415 root->fs_info->inode_root->node);
416 if (root->fs_info->tree_root->node)
417 btrfs_block_release(root->fs_info->tree_root,
418 root->fs_info->tree_root->node);
Chris Mason234b63a2007-03-13 10:46:10 -0400419 btrfs_block_release(root, root->commit_root);
Chris Masone20d96d2007-03-22 12:13:20 -0400420 btrfs_block_release(root, root->fs_info->sb_buffer);
Chris Mason87cbda52007-03-28 19:44:27 -0400421 crypto_free_hash(root->fs_info->hash_tfm);
Chris Mason30ae8462007-03-29 09:59:15 -0400422 truncate_inode_pages(root->fs_info->btree_inode->i_mapping, 0);
Chris Masond98237b2007-03-28 13:57:48 -0400423 iput(root->fs_info->btree_inode);
Chris Masone20d96d2007-03-22 12:13:20 -0400424 kfree(root->fs_info->extent_root);
425 kfree(root->fs_info->inode_root);
426 kfree(root->fs_info->tree_root);
427 kfree(root->fs_info);
428 kfree(root);
Chris Masoneb60cea2007-02-02 09:18:22 -0500429 return 0;
430}
431
Chris Masone20d96d2007-03-22 12:13:20 -0400432void btrfs_block_release(struct btrfs_root *root, struct buffer_head *buf)
Chris Masoneb60cea2007-02-02 09:18:22 -0500433{
Chris Masone20d96d2007-03-22 12:13:20 -0400434 brelse(buf);
Chris Masoneb60cea2007-02-02 09:18:22 -0500435}
436