aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-04-02 14:53:59 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-04-02 14:53:59 -0400
commit7cfcc17e7f2334a0503331264c1340de4e564c85 (patch)
tree4ce6ac8520382673006845ec20b2ad83abc9258a /fs/btrfs
parent5caf2a002901f0fde475371c4bf1c553b51884af (diff)
Btrfs: corruptions fixed
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/bit-radix.c2
-rw-r--r--fs/btrfs/disk-io.c21
-rw-r--r--fs/btrfs/inode-map.c43
-rw-r--r--fs/btrfs/super.c9
-rw-r--r--fs/btrfs/transaction.c2
5 files changed, 34 insertions, 43 deletions
diff --git a/fs/btrfs/bit-radix.c b/fs/btrfs/bit-radix.c
index a50a1c44eabd..783f54c2a16c 100644
--- a/fs/btrfs/bit-radix.c
+++ b/fs/btrfs/bit-radix.c
@@ -62,7 +62,6 @@ int clear_radix_bit(struct radix_tree_root *radix, unsigned long bit)
62 if (!bits) 62 if (!bits)
63 return 0; 63 return 0;
64 clear_bit(bit_slot, bits + 1); 64 clear_bit(bit_slot, bits + 1);
65#if 0
66 for (i = 1; i < BIT_ARRAY_BYTES / sizeof(unsigned long); i++) { 65 for (i = 1; i < BIT_ARRAY_BYTES / sizeof(unsigned long); i++) {
67 if (bits[i]) { 66 if (bits[i]) {
68 empty = 0; 67 empty = 0;
@@ -74,7 +73,6 @@ int clear_radix_bit(struct radix_tree_root *radix, unsigned long bit)
74 BUG_ON(!bits); 73 BUG_ON(!bits);
75 kmem_cache_free(btrfs_bit_radix_cachep, bits); 74 kmem_cache_free(btrfs_bit_radix_cachep, bits);
76 } 75 }
77#endif
78 return 0; 76 return 0;
79} 77}
80 78
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 2dbd55084a4e..a227e94b9e88 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -23,8 +23,6 @@ static int check_tree_block(struct btrfs_root *root, struct buffer_head *buf)
23 23
24struct buffer_head *btrfs_find_tree_block(struct btrfs_root *root, u64 blocknr) 24struct buffer_head *btrfs_find_tree_block(struct btrfs_root *root, u64 blocknr)
25{ 25{
26 return sb_find_get_block(root->fs_info->sb, blocknr);
27#if 0
28 struct address_space *mapping = root->fs_info->btree_inode->i_mapping; 26 struct address_space *mapping = root->fs_info->btree_inode->i_mapping;
29 int blockbits = root->fs_info->sb->s_blocksize_bits; 27 int blockbits = root->fs_info->sb->s_blocksize_bits;
30 unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits); 28 unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits);
@@ -58,14 +56,11 @@ out_unlock:
58 } 56 }
59 page_cache_release(page); 57 page_cache_release(page);
60 return ret; 58 return ret;
61#endif
62} 59}
63 60
64struct buffer_head *btrfs_find_create_tree_block(struct btrfs_root *root, 61struct buffer_head *btrfs_find_create_tree_block(struct btrfs_root *root,
65 u64 blocknr) 62 u64 blocknr)
66{ 63{
67 return sb_getblk(root->fs_info->sb, blocknr);
68#if 0
69 struct address_space *mapping = root->fs_info->btree_inode->i_mapping; 64 struct address_space *mapping = root->fs_info->btree_inode->i_mapping;
70 int blockbits = root->fs_info->sb->s_blocksize_bits; 65 int blockbits = root->fs_info->sb->s_blocksize_bits;
71 unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits); 66 unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits);
@@ -103,7 +98,6 @@ out_unlock:
103 touch_buffer(ret); 98 touch_buffer(ret);
104 page_cache_release(page); 99 page_cache_release(page);
105 return ret; 100 return ret;
106#endif
107} 101}
108 102
109static sector_t max_block(struct block_device *bdev) 103static sector_t max_block(struct block_device *bdev)
@@ -186,7 +180,6 @@ static int csum_tree_block(struct btrfs_root *root, struct buffer_head *bh,
186 180
187static int btree_writepage(struct page *page, struct writeback_control *wbc) 181static int btree_writepage(struct page *page, struct writeback_control *wbc)
188{ 182{
189#if 0
190 struct buffer_head *bh; 183 struct buffer_head *bh;
191 struct btrfs_root *root = btrfs_sb(page->mapping->host->i_sb); 184 struct btrfs_root *root = btrfs_sb(page->mapping->host->i_sb);
192 struct buffer_head *head; 185 struct buffer_head *head;
@@ -201,7 +194,6 @@ static int btree_writepage(struct page *page, struct writeback_control *wbc)
201 csum_tree_block(root, bh, 0); 194 csum_tree_block(root, bh, 0);
202 bh = bh->b_this_page; 195 bh = bh->b_this_page;
203 } while (bh != head); 196 } while (bh != head);
204#endif
205 return block_write_full_page(page, btree_get_block, wbc); 197 return block_write_full_page(page, btree_get_block, wbc);
206} 198}
207 199
@@ -218,8 +210,6 @@ static struct address_space_operations btree_aops = {
218 210
219struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr) 211struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr)
220{ 212{
221 return sb_bread(root->fs_info->sb, blocknr);
222#if 0
223 struct buffer_head *bh = NULL; 213 struct buffer_head *bh = NULL;
224 214
225 bh = btrfs_find_create_tree_block(root, blocknr); 215 bh = btrfs_find_create_tree_block(root, blocknr);
@@ -243,8 +233,6 @@ struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr)
243fail: 233fail:
244 brelse(bh); 234 brelse(bh);
245 return NULL; 235 return NULL;
246
247#endif
248} 236}
249 237
250int dirty_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, 238int dirty_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
@@ -323,8 +311,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
323 fs_info->last_inode_alloc = 0; 311 fs_info->last_inode_alloc = 0;
324 fs_info->last_inode_alloc_dirid = 0; 312 fs_info->last_inode_alloc_dirid = 0;
325 fs_info->sb = sb; 313 fs_info->sb = sb;
326 fs_info->btree_inode = NULL;
327#if 0
328 fs_info->btree_inode = new_inode(sb); 314 fs_info->btree_inode = new_inode(sb);
329 fs_info->btree_inode->i_ino = 1; 315 fs_info->btree_inode->i_ino = 1;
330 fs_info->btree_inode->i_nlink = 1; 316 fs_info->btree_inode->i_nlink = 1;
@@ -332,7 +318,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
332 fs_info->btree_inode->i_mapping->a_ops = &btree_aops; 318 fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
333 insert_inode_hash(fs_info->btree_inode); 319 insert_inode_hash(fs_info->btree_inode);
334 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); 320 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
335#endif
336 fs_info->hash_tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC); 321 fs_info->hash_tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
337 spin_lock_init(&fs_info->hash_lock); 322 spin_lock_init(&fs_info->hash_lock);
338 if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) { 323 if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) {
@@ -435,8 +420,8 @@ int close_ctree(struct btrfs_root *root)
435 btrfs_block_release(root, root->commit_root); 420 btrfs_block_release(root, root->commit_root);
436 btrfs_block_release(root, root->fs_info->sb_buffer); 421 btrfs_block_release(root, root->fs_info->sb_buffer);
437 crypto_free_hash(root->fs_info->hash_tfm); 422 crypto_free_hash(root->fs_info->hash_tfm);
438 // truncate_inode_pages(root->fs_info->btree_inode->i_mapping, 0); 423 truncate_inode_pages(root->fs_info->btree_inode->i_mapping, 0);
439 // iput(root->fs_info->btree_inode); 424 iput(root->fs_info->btree_inode);
440 kfree(root->fs_info->extent_root); 425 kfree(root->fs_info->extent_root);
441 kfree(root->fs_info->inode_root); 426 kfree(root->fs_info->inode_root);
442 kfree(root->fs_info->tree_root); 427 kfree(root->fs_info->tree_root);
@@ -447,6 +432,6 @@ int close_ctree(struct btrfs_root *root)
447 432
448void btrfs_block_release(struct btrfs_root *root, struct buffer_head *buf) 433void btrfs_block_release(struct btrfs_root *root, struct buffer_head *buf)
449{ 434{
450 // brelse(buf); 435 brelse(buf);
451} 436}
452 437
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index fa4adb81b149..b3de823eb628 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -10,7 +10,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
10 struct btrfs_root *fs_root, 10 struct btrfs_root *fs_root,
11 u64 dirid, u64 *objectid) 11 u64 dirid, u64 *objectid)
12{ 12{
13 struct btrfs_path path; 13 struct btrfs_path *path;
14 struct btrfs_key key; 14 struct btrfs_key key;
15 int ret; 15 int ret;
16 u64 hole_size = 0; 16 u64 hole_size = 0;
@@ -31,20 +31,22 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
31 btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY); 31 btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY);
32 search_key.offset = 0; 32 search_key.offset = 0;
33 33
34 btrfs_init_path(&path); 34 path = btrfs_alloc_path();
35 BUG_ON(!path);
36 btrfs_init_path(path);
35 start_found = 0; 37 start_found = 0;
36 ret = btrfs_search_slot(trans, root, &search_key, &path, 0, 0); 38 ret = btrfs_search_slot(trans, root, &search_key, path, 0, 0);
37 if (ret < 0) 39 if (ret < 0)
38 goto error; 40 goto error;
39 41
40 if (path.slots[0] > 0) 42 if (path->slots[0] > 0)
41 path.slots[0]--; 43 path->slots[0]--;
42 44
43 while (1) { 45 while (1) {
44 l = btrfs_buffer_leaf(path.nodes[0]); 46 l = btrfs_buffer_leaf(path->nodes[0]);
45 slot = path.slots[0]; 47 slot = path->slots[0];
46 if (slot >= btrfs_header_nritems(&l->header)) { 48 if (slot >= btrfs_header_nritems(&l->header)) {
47 ret = btrfs_next_leaf(root, &path); 49 ret = btrfs_next_leaf(root, path);
48 if (ret == 0) 50 if (ret == 0)
49 continue; 51 continue;
50 if (ret < 0) 52 if (ret < 0)
@@ -72,17 +74,19 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
72 } 74 }
73 start_found = 1; 75 start_found = 1;
74 last_ino = key.objectid + 1; 76 last_ino = key.objectid + 1;
75 path.slots[0]++; 77 path->slots[0]++;
76 } 78 }
77 // FIXME -ENOSPC 79 // FIXME -ENOSPC
78found: 80found:
79 root->fs_info->last_inode_alloc = *objectid; 81 root->fs_info->last_inode_alloc = *objectid;
80 root->fs_info->last_inode_alloc_dirid = dirid; 82 root->fs_info->last_inode_alloc_dirid = dirid;
81 btrfs_release_path(root, &path); 83 btrfs_release_path(root, path);
84 btrfs_free_path(path);
82 BUG_ON(*objectid < search_start); 85 BUG_ON(*objectid < search_start);
83 return 0; 86 return 0;
84error: 87error:
85 btrfs_release_path(root, &path); 88 btrfs_release_path(root, path);
89 btrfs_free_path(path);
86 return ret; 90 return ret;
87} 91}
88 92
@@ -91,7 +95,7 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
91 u64 objectid, struct btrfs_key *location) 95 u64 objectid, struct btrfs_key *location)
92{ 96{
93 int ret = 0; 97 int ret = 0;
94 struct btrfs_path path; 98 struct btrfs_path *path;
95 struct btrfs_inode_map_item *inode_item; 99 struct btrfs_inode_map_item *inode_item;
96 struct btrfs_key key; 100 struct btrfs_key key;
97 struct btrfs_root *inode_root = fs_root->fs_info->inode_root; 101 struct btrfs_root *inode_root = fs_root->fs_info->inode_root;
@@ -100,18 +104,21 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
100 key.flags = 0; 104 key.flags = 0;
101 btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY); 105 btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY);
102 key.offset = 0; 106 key.offset = 0;
103 btrfs_init_path(&path); 107 path = btrfs_alloc_path();
104 ret = btrfs_insert_empty_item(trans, inode_root, &path, &key, 108 BUG_ON(!path);
109 btrfs_init_path(path);
110 ret = btrfs_insert_empty_item(trans, inode_root, path, &key,
105 sizeof(struct btrfs_inode_map_item)); 111 sizeof(struct btrfs_inode_map_item));
106 if (ret) 112 if (ret)
107 goto out; 113 goto out;
108 114
109 inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]), 115 inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
110 path.slots[0], struct btrfs_inode_map_item); 116 path->slots[0], struct btrfs_inode_map_item);
111 btrfs_cpu_key_to_disk(&inode_item->key, location); 117 btrfs_cpu_key_to_disk(&inode_item->key, location);
112 btrfs_mark_buffer_dirty(path.nodes[0]); 118 btrfs_mark_buffer_dirty(path->nodes[0]);
113out: 119out:
114 btrfs_release_path(inode_root, &path); 120 btrfs_release_path(inode_root, path);
121 btrfs_free_path(path);
115 return ret; 122 return ret;
116} 123}
117 124
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index c260fcad17b3..9fd87f5edbc9 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -49,6 +49,7 @@ static void btrfs_read_locked_inode(struct inode *inode)
49 ret = btrfs_lookup_inode(NULL, root, path, inode->i_ino, 0); 49 ret = btrfs_lookup_inode(NULL, root, path, inode->i_ino, 0);
50 if (ret) { 50 if (ret) {
51 btrfs_release_path(root, path); 51 btrfs_release_path(root, path);
52 btrfs_free_path(path);
52 mutex_unlock(&root->fs_info->fs_mutex); 53 mutex_unlock(&root->fs_info->fs_mutex);
53 make_bad_inode(inode); 54 make_bad_inode(inode);
54 return; 55 return;
@@ -215,7 +216,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
215 goto out; 216 goto out;
216 } 217 }
217 btrfs_release_path(root, path); 218 btrfs_release_path(root, path);
218 btrfs_free_path(path);
219 219
220 /* now the directory is empty */ 220 /* now the directory is empty */
221 err = btrfs_unlink_trans(trans, root, dir, dentry); 221 err = btrfs_unlink_trans(trans, root, dir, dentry);
@@ -223,6 +223,8 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
223 inode->i_size = 0; 223 inode->i_size = 0;
224 } 224 }
225out: 225out:
226 btrfs_release_path(root, path);
227 btrfs_free_path(path);
226 mutex_unlock(&root->fs_info->fs_mutex); 228 mutex_unlock(&root->fs_info->fs_mutex);
227 ret = btrfs_end_transaction(trans, root); 229 ret = btrfs_end_transaction(trans, root);
228 if (ret && !err) 230 if (ret && !err)
@@ -800,11 +802,10 @@ static int btrfs_sync_fs(struct super_block *sb, int wait)
800 802
801 sb->s_dirt = 0; 803 sb->s_dirt = 0;
802 if (!wait) { 804 if (!wait) {
803 // filemap_flush(root->fs_info->btree_inode->i_mapping); 805 filemap_flush(root->fs_info->btree_inode->i_mapping);
804 filemap_flush(root->fs_info->sb->s_bdev->bd_inode->i_mapping);
805 return 0; 806 return 0;
806 } 807 }
807 filemap_write_and_wait(root->fs_info->sb->s_bdev->bd_inode->i_mapping); 808 filemap_write_and_wait(root->fs_info->btree_inode->i_mapping);
808 mutex_lock(&root->fs_info->fs_mutex); 809 mutex_lock(&root->fs_info->fs_mutex);
809 trans = btrfs_start_transaction(root, 1); 810 trans = btrfs_start_transaction(root, 1);
810 ret = btrfs_commit_transaction(trans, root); 811 ret = btrfs_commit_transaction(trans, root);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 72b52e1e0b1b..2b0f98c92123 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -88,7 +88,7 @@ int btrfs_end_transaction(struct btrfs_trans_handle *trans,
88int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, 88int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
89 struct btrfs_root *root) 89 struct btrfs_root *root)
90{ 90{
91 filemap_write_and_wait(root->fs_info->sb->s_bdev->bd_inode->i_mapping); 91 filemap_write_and_wait(root->fs_info->btree_inode->i_mapping);
92 return 0; 92 return 0;
93} 93}
94 94