Commit 7cfcc17e authored by Chris Mason's avatar Chris Mason Committed by David Woodhouse

Btrfs: corruptions fixed

Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 5caf2a00
...@@ -62,7 +62,6 @@ int clear_radix_bit(struct radix_tree_root *radix, unsigned long bit) ...@@ -62,7 +62,6 @@ int clear_radix_bit(struct radix_tree_root *radix, unsigned long bit)
if (!bits) if (!bits)
return 0; return 0;
clear_bit(bit_slot, bits + 1); clear_bit(bit_slot, bits + 1);
#if 0
for (i = 1; i < BIT_ARRAY_BYTES / sizeof(unsigned long); i++) { for (i = 1; i < BIT_ARRAY_BYTES / sizeof(unsigned long); i++) {
if (bits[i]) { if (bits[i]) {
empty = 0; empty = 0;
...@@ -74,7 +73,6 @@ int clear_radix_bit(struct radix_tree_root *radix, unsigned long bit) ...@@ -74,7 +73,6 @@ int clear_radix_bit(struct radix_tree_root *radix, unsigned long bit)
BUG_ON(!bits); BUG_ON(!bits);
kmem_cache_free(btrfs_bit_radix_cachep, bits); kmem_cache_free(btrfs_bit_radix_cachep, bits);
} }
#endif
return 0; return 0;
} }
......
...@@ -23,8 +23,6 @@ static int check_tree_block(struct btrfs_root *root, struct buffer_head *buf) ...@@ -23,8 +23,6 @@ static int check_tree_block(struct btrfs_root *root, struct buffer_head *buf)
struct buffer_head *btrfs_find_tree_block(struct btrfs_root *root, u64 blocknr) struct buffer_head *btrfs_find_tree_block(struct btrfs_root *root, u64 blocknr)
{ {
return sb_find_get_block(root->fs_info->sb, blocknr);
#if 0
struct address_space *mapping = root->fs_info->btree_inode->i_mapping; struct address_space *mapping = root->fs_info->btree_inode->i_mapping;
int blockbits = root->fs_info->sb->s_blocksize_bits; int blockbits = root->fs_info->sb->s_blocksize_bits;
unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits); unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits);
...@@ -58,14 +56,11 @@ struct buffer_head *btrfs_find_tree_block(struct btrfs_root *root, u64 blocknr) ...@@ -58,14 +56,11 @@ struct buffer_head *btrfs_find_tree_block(struct btrfs_root *root, u64 blocknr)
} }
page_cache_release(page); page_cache_release(page);
return ret; return ret;
#endif
} }
struct buffer_head *btrfs_find_create_tree_block(struct btrfs_root *root, struct buffer_head *btrfs_find_create_tree_block(struct btrfs_root *root,
u64 blocknr) u64 blocknr)
{ {
return sb_getblk(root->fs_info->sb, blocknr);
#if 0
struct address_space *mapping = root->fs_info->btree_inode->i_mapping; struct address_space *mapping = root->fs_info->btree_inode->i_mapping;
int blockbits = root->fs_info->sb->s_blocksize_bits; int blockbits = root->fs_info->sb->s_blocksize_bits;
unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits); unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits);
...@@ -103,7 +98,6 @@ struct buffer_head *btrfs_find_create_tree_block(struct btrfs_root *root, ...@@ -103,7 +98,6 @@ struct buffer_head *btrfs_find_create_tree_block(struct btrfs_root *root,
touch_buffer(ret); touch_buffer(ret);
page_cache_release(page); page_cache_release(page);
return ret; return ret;
#endif
} }
static sector_t max_block(struct block_device *bdev) static 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,7 +180,6 @@ static int csum_tree_block(struct btrfs_root *root, struct buffer_head *bh,
static int btree_writepage(struct page *page, struct writeback_control *wbc) static int btree_writepage(struct page *page, struct writeback_control *wbc)
{ {
#if 0
struct buffer_head *bh; struct buffer_head *bh;
struct btrfs_root *root = btrfs_sb(page->mapping->host->i_sb); struct btrfs_root *root = btrfs_sb(page->mapping->host->i_sb);
struct buffer_head *head; struct buffer_head *head;
...@@ -201,7 +194,6 @@ static int btree_writepage(struct page *page, struct writeback_control *wbc) ...@@ -201,7 +194,6 @@ static int btree_writepage(struct page *page, struct writeback_control *wbc)
csum_tree_block(root, bh, 0); csum_tree_block(root, bh, 0);
bh = bh->b_this_page; bh = bh->b_this_page;
} while (bh != head); } while (bh != head);
#endif
return block_write_full_page(page, btree_get_block, wbc); return block_write_full_page(page, btree_get_block, wbc);
} }
...@@ -218,8 +210,6 @@ static struct address_space_operations btree_aops = { ...@@ -218,8 +210,6 @@ static struct address_space_operations btree_aops = {
struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr) struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr)
{ {
return sb_bread(root->fs_info->sb, blocknr);
#if 0
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
bh = btrfs_find_create_tree_block(root, blocknr); bh = btrfs_find_create_tree_block(root, blocknr);
...@@ -243,8 +233,6 @@ struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr) ...@@ -243,8 +233,6 @@ struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr)
fail: fail:
brelse(bh); brelse(bh);
return NULL; return NULL;
#endif
} }
int dirty_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, int 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,8 +311,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
fs_info->last_inode_alloc = 0; fs_info->last_inode_alloc = 0;
fs_info->last_inode_alloc_dirid = 0; fs_info->last_inode_alloc_dirid = 0;
fs_info->sb = sb; fs_info->sb = sb;
fs_info->btree_inode = NULL;
#if 0
fs_info->btree_inode = new_inode(sb); fs_info->btree_inode = new_inode(sb);
fs_info->btree_inode->i_ino = 1; fs_info->btree_inode->i_ino = 1;
fs_info->btree_inode->i_nlink = 1; fs_info->btree_inode->i_nlink = 1;
...@@ -332,7 +318,6 @@ struct btrfs_root *open_ctree(struct super_block *sb) ...@@ -332,7 +318,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
fs_info->btree_inode->i_mapping->a_ops = &btree_aops; fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
insert_inode_hash(fs_info->btree_inode); insert_inode_hash(fs_info->btree_inode);
mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
#endif
fs_info->hash_tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC); fs_info->hash_tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
spin_lock_init(&fs_info->hash_lock); spin_lock_init(&fs_info->hash_lock);
if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) { if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) {
...@@ -435,8 +420,8 @@ int close_ctree(struct btrfs_root *root) ...@@ -435,8 +420,8 @@ int close_ctree(struct btrfs_root *root)
btrfs_block_release(root, root->commit_root); btrfs_block_release(root, root->commit_root);
btrfs_block_release(root, root->fs_info->sb_buffer); btrfs_block_release(root, root->fs_info->sb_buffer);
crypto_free_hash(root->fs_info->hash_tfm); crypto_free_hash(root->fs_info->hash_tfm);
// truncate_inode_pages(root->fs_info->btree_inode->i_mapping, 0); truncate_inode_pages(root->fs_info->btree_inode->i_mapping, 0);
// iput(root->fs_info->btree_inode); iput(root->fs_info->btree_inode);
kfree(root->fs_info->extent_root); kfree(root->fs_info->extent_root);
kfree(root->fs_info->inode_root); kfree(root->fs_info->inode_root);
kfree(root->fs_info->tree_root); kfree(root->fs_info->tree_root);
...@@ -447,6 +432,6 @@ int close_ctree(struct btrfs_root *root) ...@@ -447,6 +432,6 @@ int close_ctree(struct btrfs_root *root)
void btrfs_block_release(struct btrfs_root *root, struct buffer_head *buf) void btrfs_block_release(struct btrfs_root *root, struct buffer_head *buf)
{ {
// brelse(buf); brelse(buf);
} }
...@@ -10,7 +10,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, ...@@ -10,7 +10,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
struct btrfs_root *fs_root, struct btrfs_root *fs_root,
u64 dirid, u64 *objectid) u64 dirid, u64 *objectid)
{ {
struct btrfs_path path; struct btrfs_path *path;
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
u64 hole_size = 0; u64 hole_size = 0;
...@@ -31,20 +31,22 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, ...@@ -31,20 +31,22 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY); btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY);
search_key.offset = 0; search_key.offset = 0;
btrfs_init_path(&path); path = btrfs_alloc_path();
BUG_ON(!path);
btrfs_init_path(path);
start_found = 0; start_found = 0;
ret = btrfs_search_slot(trans, root, &search_key, &path, 0, 0); ret = btrfs_search_slot(trans, root, &search_key, path, 0, 0);
if (ret < 0) if (ret < 0)
goto error; goto error;
if (path.slots[0] > 0) if (path->slots[0] > 0)
path.slots[0]--; path->slots[0]--;
while (1) { while (1) {
l = btrfs_buffer_leaf(path.nodes[0]); l = btrfs_buffer_leaf(path->nodes[0]);
slot = path.slots[0]; slot = path->slots[0];
if (slot >= btrfs_header_nritems(&l->header)) { if (slot >= btrfs_header_nritems(&l->header)) {
ret = btrfs_next_leaf(root, &path); ret = btrfs_next_leaf(root, path);
if (ret == 0) if (ret == 0)
continue; continue;
if (ret < 0) if (ret < 0)
...@@ -72,17 +74,19 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, ...@@ -72,17 +74,19 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
} }
start_found = 1; start_found = 1;
last_ino = key.objectid + 1; last_ino = key.objectid + 1;
path.slots[0]++; path->slots[0]++;
} }
// FIXME -ENOSPC // FIXME -ENOSPC
found: found:
root->fs_info->last_inode_alloc = *objectid; root->fs_info->last_inode_alloc = *objectid;
root->fs_info->last_inode_alloc_dirid = dirid; root->fs_info->last_inode_alloc_dirid = dirid;
btrfs_release_path(root, &path); btrfs_release_path(root, path);
btrfs_free_path(path);
BUG_ON(*objectid < search_start); BUG_ON(*objectid < search_start);
return 0; return 0;
error: error:
btrfs_release_path(root, &path); btrfs_release_path(root, path);
btrfs_free_path(path);
return ret; return ret;
} }
...@@ -91,7 +95,7 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans, ...@@ -91,7 +95,7 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
u64 objectid, struct btrfs_key *location) u64 objectid, struct btrfs_key *location)
{ {
int ret = 0; int ret = 0;
struct btrfs_path path; struct btrfs_path *path;
struct btrfs_inode_map_item *inode_item; struct btrfs_inode_map_item *inode_item;
struct btrfs_key key; struct btrfs_key key;
struct btrfs_root *inode_root = fs_root->fs_info->inode_root; 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,18 +104,21 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
key.flags = 0; key.flags = 0;
btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY); btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY);
key.offset = 0; key.offset = 0;
btrfs_init_path(&path); path = btrfs_alloc_path();
ret = btrfs_insert_empty_item(trans, inode_root, &path, &key, BUG_ON(!path);
btrfs_init_path(path);
ret = btrfs_insert_empty_item(trans, inode_root, path, &key,
sizeof(struct btrfs_inode_map_item)); sizeof(struct btrfs_inode_map_item));
if (ret) if (ret)
goto out; goto out;
inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]), inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
path.slots[0], struct btrfs_inode_map_item); path->slots[0], struct btrfs_inode_map_item);
btrfs_cpu_key_to_disk(&inode_item->key, location); btrfs_cpu_key_to_disk(&inode_item->key, location);
btrfs_mark_buffer_dirty(path.nodes[0]); btrfs_mark_buffer_dirty(path->nodes[0]);
out: out:
btrfs_release_path(inode_root, &path); btrfs_release_path(inode_root, path);
btrfs_free_path(path);
return ret; return ret;
} }
......
...@@ -49,6 +49,7 @@ static void btrfs_read_locked_inode(struct inode *inode) ...@@ -49,6 +49,7 @@ static void btrfs_read_locked_inode(struct inode *inode)
ret = btrfs_lookup_inode(NULL, root, path, inode->i_ino, 0); ret = btrfs_lookup_inode(NULL, root, path, inode->i_ino, 0);
if (ret) { if (ret) {
btrfs_release_path(root, path); btrfs_release_path(root, path);
btrfs_free_path(path);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
make_bad_inode(inode); make_bad_inode(inode);
return; return;
...@@ -215,7 +216,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -215,7 +216,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
goto out; goto out;
} }
btrfs_release_path(root, path); btrfs_release_path(root, path);
btrfs_free_path(path);
/* now the directory is empty */ /* now the directory is empty */
err = btrfs_unlink_trans(trans, root, dir, dentry); err = btrfs_unlink_trans(trans, root, dir, dentry);
...@@ -223,6 +223,8 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -223,6 +223,8 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
inode->i_size = 0; inode->i_size = 0;
} }
out: out:
btrfs_release_path(root, path);
btrfs_free_path(path);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
ret = btrfs_end_transaction(trans, root); ret = btrfs_end_transaction(trans, root);
if (ret && !err) if (ret && !err)
...@@ -800,11 +802,10 @@ static int btrfs_sync_fs(struct super_block *sb, int wait) ...@@ -800,11 +802,10 @@ static int btrfs_sync_fs(struct super_block *sb, int wait)
sb->s_dirt = 0; sb->s_dirt = 0;
if (!wait) { if (!wait) {
// filemap_flush(root->fs_info->btree_inode->i_mapping); filemap_flush(root->fs_info->btree_inode->i_mapping);
filemap_flush(root->fs_info->sb->s_bdev->bd_inode->i_mapping);
return 0; return 0;
} }
filemap_write_and_wait(root->fs_info->sb->s_bdev->bd_inode->i_mapping); filemap_write_and_wait(root->fs_info->btree_inode->i_mapping);
mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->fs_mutex);
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
ret = btrfs_commit_transaction(trans, root); ret = btrfs_commit_transaction(trans, root);
......
...@@ -88,7 +88,7 @@ int btrfs_end_transaction(struct btrfs_trans_handle *trans, ...@@ -88,7 +88,7 @@ int btrfs_end_transaction(struct btrfs_trans_handle *trans,
int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
struct btrfs_root *root) struct btrfs_root *root)
{ {
filemap_write_and_wait(root->fs_info->sb->s_bdev->bd_inode->i_mapping); filemap_write_and_wait(root->fs_info->btree_inode->i_mapping);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment