summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-04-02 18:53:59 (GMT)
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-04-02 18:53:59 (GMT)
commit7cfcc17e7f2334a0503331264c1340de4e564c85 (patch)
tree4ce6ac8520382673006845ec20b2ad83abc9258a
parent5caf2a002901f0fde475371c4bf1c553b51884af (diff)
downloadlinux-7cfcc17e7f2334a0503331264c1340de4e564c85.tar.xz
Btrfs: corruptions fixed
Signed-off-by: Chris Mason <chris.mason@oracle.com>
-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 a50a1c4..783f54c 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)
if (!bits)
return 0;
clear_bit(bit_slot, bits + 1);
-#if 0
for (i = 1; i < BIT_ARRAY_BYTES / sizeof(unsigned long); i++) {
if (bits[i]) {
empty = 0;
@@ -74,7 +73,6 @@ int clear_radix_bit(struct radix_tree_root *radix, unsigned long bit)
BUG_ON(!bits);
kmem_cache_free(btrfs_bit_radix_cachep, bits);
}
-#endif
return 0;
}
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 2dbd550..a227e94 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)
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;
int blockbits = root->fs_info->sb->s_blocksize_bits;
unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits);
@@ -58,14 +56,11 @@ out_unlock:
}
page_cache_release(page);
return ret;
-#endif
}
struct buffer_head *btrfs_find_create_tree_block(struct btrfs_root *root,
u64 blocknr)
{
- return sb_getblk(root->fs_info->sb, blocknr);
-#if 0
struct address_space *mapping = root->fs_info->btree_inode->i_mapping;
int blockbits = root->fs_info->sb->s_blocksize_bits;
unsigned long index = blocknr >> (PAGE_CACHE_SHIFT - blockbits);
@@ -103,7 +98,6 @@ out_unlock:
touch_buffer(ret);
page_cache_release(page);
return ret;
-#endif
}
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,
static int btree_writepage(struct page *page, struct writeback_control *wbc)
{
-#if 0
struct buffer_head *bh;
struct btrfs_root *root = btrfs_sb(page->mapping->host->i_sb);
struct buffer_head *head;
@@ -201,7 +194,6 @@ static int btree_writepage(struct page *page, struct writeback_control *wbc)
csum_tree_block(root, bh, 0);
bh = bh->b_this_page;
} while (bh != head);
-#endif
return block_write_full_page(page, btree_get_block, wbc);
}
@@ -218,8 +210,6 @@ static struct address_space_operations btree_aops = {
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;
bh = btrfs_find_create_tree_block(root, blocknr);
@@ -243,8 +233,6 @@ struct buffer_head *read_tree_block(struct btrfs_root *root, u64 blocknr)
fail:
brelse(bh);
return NULL;
-
-#endif
}
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)
fs_info->last_inode_alloc = 0;
fs_info->last_inode_alloc_dirid = 0;
fs_info->sb = sb;
- fs_info->btree_inode = NULL;
-#if 0
fs_info->btree_inode = new_inode(sb);
fs_info->btree_inode->i_ino = 1;
fs_info->btree_inode->i_nlink = 1;
@@ -332,7 +318,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
insert_inode_hash(fs_info->btree_inode);
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);
spin_lock_init(&fs_info->hash_lock);
if (!fs_info->hash_tfm || IS_ERR(fs_info->hash_tfm)) {
@@ -435,8 +420,8 @@ int close_ctree(struct btrfs_root *root)
btrfs_block_release(root, root->commit_root);
btrfs_block_release(root, root->fs_info->sb_buffer);
crypto_free_hash(root->fs_info->hash_tfm);
- // truncate_inode_pages(root->fs_info->btree_inode->i_mapping, 0);
- // iput(root->fs_info->btree_inode);
+ truncate_inode_pages(root->fs_info->btree_inode->i_mapping, 0);
+ iput(root->fs_info->btree_inode);
kfree(root->fs_info->extent_root);
kfree(root->fs_info->inode_root);
kfree(root->fs_info->tree_root);
@@ -447,6 +432,6 @@ int close_ctree(struct btrfs_root *root)
void btrfs_block_release(struct btrfs_root *root, struct buffer_head *buf)
{
- // brelse(buf);
+ brelse(buf);
}
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index fa4adb8..b3de823 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,
struct btrfs_root *fs_root,
u64 dirid, u64 *objectid)
{
- struct btrfs_path path;
+ struct btrfs_path *path;
struct btrfs_key key;
int ret;
u64 hole_size = 0;
@@ -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);
search_key.offset = 0;
- btrfs_init_path(&path);
+ path = btrfs_alloc_path();
+ BUG_ON(!path);
+ btrfs_init_path(path);
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)
goto error;
- if (path.slots[0] > 0)
- path.slots[0]--;
+ if (path->slots[0] > 0)
+ path->slots[0]--;
while (1) {
- l = btrfs_buffer_leaf(path.nodes[0]);
- slot = path.slots[0];
+ l = btrfs_buffer_leaf(path->nodes[0]);
+ slot = path->slots[0];
if (slot >= btrfs_header_nritems(&l->header)) {
- ret = btrfs_next_leaf(root, &path);
+ ret = btrfs_next_leaf(root, path);
if (ret == 0)
continue;
if (ret < 0)
@@ -72,17 +74,19 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
}
start_found = 1;
last_ino = key.objectid + 1;
- path.slots[0]++;
+ path->slots[0]++;
}
// FIXME -ENOSPC
found:
root->fs_info->last_inode_alloc = *objectid;
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);
return 0;
error:
- btrfs_release_path(root, &path);
+ btrfs_release_path(root, path);
+ btrfs_free_path(path);
return ret;
}
@@ -91,7 +95,7 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
u64 objectid, struct btrfs_key *location)
{
int ret = 0;
- struct btrfs_path path;
+ struct btrfs_path *path;
struct btrfs_inode_map_item *inode_item;
struct btrfs_key key;
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,
key.flags = 0;
btrfs_set_key_type(&key, BTRFS_INODE_MAP_ITEM_KEY);
key.offset = 0;
- btrfs_init_path(&path);
- ret = btrfs_insert_empty_item(trans, inode_root, &path, &key,
+ path = btrfs_alloc_path();
+ BUG_ON(!path);
+ btrfs_init_path(path);
+ ret = btrfs_insert_empty_item(trans, inode_root, path, &key,
sizeof(struct btrfs_inode_map_item));
if (ret)
goto out;
- inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]),
- path.slots[0], struct btrfs_inode_map_item);
+ inode_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
+ path->slots[0], struct btrfs_inode_map_item);
btrfs_cpu_key_to_disk(&inode_item->key, location);
- btrfs_mark_buffer_dirty(path.nodes[0]);
+ btrfs_mark_buffer_dirty(path->nodes[0]);
out:
- btrfs_release_path(inode_root, &path);
+ btrfs_release_path(inode_root, path);
+ btrfs_free_path(path);
return ret;
}
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index c260fca..9fd87f5 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -49,6 +49,7 @@ static void btrfs_read_locked_inode(struct inode *inode)
ret = btrfs_lookup_inode(NULL, root, path, inode->i_ino, 0);
if (ret) {
btrfs_release_path(root, path);
+ btrfs_free_path(path);
mutex_unlock(&root->fs_info->fs_mutex);
make_bad_inode(inode);
return;
@@ -215,7 +216,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
goto out;
}
btrfs_release_path(root, path);
- btrfs_free_path(path);
/* now the directory is empty */
err = btrfs_unlink_trans(trans, root, dir, dentry);
@@ -223,6 +223,8 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
inode->i_size = 0;
}
out:
+ btrfs_release_path(root, path);
+ btrfs_free_path(path);
mutex_unlock(&root->fs_info->fs_mutex);
ret = btrfs_end_transaction(trans, root);
if (ret && !err)
@@ -800,11 +802,10 @@ static int btrfs_sync_fs(struct super_block *sb, int wait)
sb->s_dirt = 0;
if (!wait) {
- // filemap_flush(root->fs_info->btree_inode->i_mapping);
- filemap_flush(root->fs_info->sb->s_bdev->bd_inode->i_mapping);
+ filemap_flush(root->fs_info->btree_inode->i_mapping);
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);
trans = btrfs_start_transaction(root, 1);
ret = btrfs_commit_transaction(trans, root);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 72b52e1..2b0f98c 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -88,7 +88,7 @@ int btrfs_end_transaction(struct btrfs_trans_handle *trans,
int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
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;
}