btrfs: get fs_info from eb in btrfs_check_node
[sfrench/cifs-2.6.git] / fs / btrfs / disk-io.c
index f4ef3a1a321b296f68e5584dc3f7f9d5d5e6d421..36c44ddadd2d33cccd5db235fef56ee8076b8610 100644 (file)
@@ -394,10 +394,10 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
        return ret;
 }
 
-int btrfs_verify_level_key(struct btrfs_fs_info *fs_info,
-                          struct extent_buffer *eb, int level,
+int btrfs_verify_level_key(struct extent_buffer *eb, int level,
                           struct btrfs_key *first_key, u64 parent_transid)
 {
+       struct btrfs_fs_info *fs_info = eb->fs_info;
        int found_level;
        struct btrfs_key found_key;
        int ret;
@@ -450,11 +450,11 @@ int btrfs_verify_level_key(struct btrfs_fs_info *fs_info,
  * @level:             expected level, mandatory check
  * @first_key:         expected key of first slot, skip check if NULL
  */
-static int btree_read_extent_buffer_pages(struct btrfs_fs_info *fs_info,
-                                         struct extent_buffer *eb,
+static int btree_read_extent_buffer_pages(struct extent_buffer *eb,
                                          u64 parent_transid, int level,
                                          struct btrfs_key *first_key)
 {
+       struct btrfs_fs_info *fs_info = eb->fs_info;
        struct extent_io_tree *io_tree;
        int failed = 0;
        int ret;
@@ -471,7 +471,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_fs_info *fs_info,
                        if (verify_parent_transid(io_tree, eb,
                                                   parent_transid, 0))
                                ret = -EIO;
-                       else if (btrfs_verify_level_key(fs_info, eb, level,
+                       else if (btrfs_verify_level_key(eb, level,
                                                first_key, parent_transid))
                                ret = -EUCLEAN;
                        else
@@ -497,7 +497,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_fs_info *fs_info,
        }
 
        if (failed && !ret && failed_mirror)
-               repair_eb_io_failure(fs_info, eb, failed_mirror);
+               btrfs_repair_eb_io_failure(eb, failed_mirror);
 
        return ret;
 }
@@ -539,9 +539,9 @@ static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct page *page)
        return 0;
 }
 
-static int check_tree_block_fsid(struct btrfs_fs_info *fs_info,
-                                struct extent_buffer *eb)
+static int check_tree_block_fsid(struct extent_buffer *eb)
 {
+       struct btrfs_fs_info *fs_info = eb->fs_info;
        struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
        u8 fsid[BTRFS_FSID_SIZE];
        int ret = 1;
@@ -611,7 +611,7 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
                ret = -EIO;
                goto err;
        }
-       if (check_tree_block_fsid(fs_info, eb)) {
+       if (check_tree_block_fsid(eb)) {
                btrfs_err_rl(fs_info, "bad fsid on block %llu",
                             eb->start);
                ret = -EIO;
@@ -652,12 +652,12 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
         * that we don't try and read the other copies of this block, just
         * return -EIO.
         */
-       if (found_level == 0 && btrfs_check_leaf_full(fs_info, eb)) {
+       if (found_level == 0 && btrfs_check_leaf_full(eb)) {
                set_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags);
                ret = -EIO;
        }
 
-       if (found_level > 0 && btrfs_check_node(fs_info, eb))
+       if (found_level > 0 && btrfs_check_node(eb))
                ret = -EIO;
 
        if (!ret)
@@ -1078,19 +1078,6 @@ struct extent_buffer *btrfs_find_create_tree_block(
        return alloc_extent_buffer(fs_info, bytenr);
 }
 
-
-int btrfs_write_tree_block(struct extent_buffer *buf)
-{
-       return filemap_fdatawrite_range(buf->pages[0]->mapping, buf->start,
-                                       buf->start + buf->len - 1);
-}
-
-void btrfs_wait_tree_block_writeback(struct extent_buffer *buf)
-{
-       filemap_fdatawait_range(buf->pages[0]->mapping,
-                               buf->start, buf->start + buf->len - 1);
-}
-
 /*
  * Read tree block at logical address @bytenr and do variant basic but critical
  * verification.
@@ -1110,7 +1097,7 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
        if (IS_ERR(buf))
                return buf;
 
-       ret = btree_read_extent_buffer_pages(fs_info, buf, parent_transid,
+       ret = btree_read_extent_buffer_pages(buf, parent_transid,
                                             level, first_key);
        if (ret) {
                free_extent_buffer_stale(buf);
@@ -1120,9 +1107,9 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
 
 }
 
-void clean_tree_block(struct btrfs_fs_info *fs_info,
-                     struct extent_buffer *buf)
+void btrfs_clean_tree_block(struct extent_buffer *buf)
 {
+       struct btrfs_fs_info *fs_info = buf->fs_info;
        if (btrfs_header_generation(buf) ==
            fs_info->running_transaction->transid) {
                btrfs_assert_tree_locked(buf);
@@ -2174,7 +2161,6 @@ static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info)
        spin_lock_init(&fs_info->qgroup_lock);
        mutex_init(&fs_info->qgroup_ioctl_lock);
        fs_info->qgroup_tree = RB_ROOT;
-       fs_info->qgroup_op_tree = RB_ROOT;
        INIT_LIST_HEAD(&fs_info->dirty_qgroups);
        fs_info->qgroup_seq = 1;
        fs_info->qgroup_ulist = NULL;
@@ -2679,7 +2665,6 @@ int open_ctree(struct super_block *sb,
        spin_lock_init(&fs_info->defrag_inodes_lock);
        spin_lock_init(&fs_info->tree_mod_seq_lock);
        spin_lock_init(&fs_info->super_lock);
-       spin_lock_init(&fs_info->qgroup_op_lock);
        spin_lock_init(&fs_info->buffer_lock);
        spin_lock_init(&fs_info->unused_bgs_lock);
        rwlock_init(&fs_info->tree_mod_log_lock);
@@ -2706,7 +2691,6 @@ int open_ctree(struct super_block *sb,
 
        atomic_set(&fs_info->async_delalloc_pages, 0);
        atomic_set(&fs_info->defrag_running, 0);
-       atomic_set(&fs_info->qgroup_op_seq, 0);
        atomic_set(&fs_info->reada_works_cnt, 0);
        atomic_set(&fs_info->nr_delayed_iputs, 0);
        atomic64_set(&fs_info->tree_mod_seq, 0);
@@ -2790,8 +2774,6 @@ int open_ctree(struct super_block *sb,
        init_waitqueue_head(&fs_info->async_submit_wait);
        init_waitqueue_head(&fs_info->delayed_iputs_wait);
 
-       INIT_LIST_HEAD(&fs_info->pinned_chunks);
-
        /* Usable values until the real ones are cached from the superblock */
        fs_info->nodesize = 4096;
        fs_info->sectorsize = 4096;
@@ -4056,8 +4038,8 @@ void close_ctree(struct btrfs_fs_info *fs_info)
                btrfsic_unmount(fs_info->fs_devices);
 #endif
 
-       btrfs_close_devices(fs_info->fs_devices);
        btrfs_mapping_tree_free(&fs_info->mapping_tree);
+       btrfs_close_devices(fs_info->fs_devices);
 
        percpu_counter_destroy(&fs_info->dirty_metadata_bytes);
        percpu_counter_destroy(&fs_info->delalloc_bytes);
@@ -4066,15 +4048,6 @@ void close_ctree(struct btrfs_fs_info *fs_info)
 
        btrfs_free_stripe_hash_table(fs_info);
        btrfs_free_ref_cache(fs_info);
-
-       while (!list_empty(&fs_info->pinned_chunks)) {
-               struct extent_map *em;
-
-               em = list_first_entry(&fs_info->pinned_chunks,
-                                     struct extent_map, list);
-               list_del_init(&em->list);
-               free_extent_map(em);
-       }
 }
 
 int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
@@ -4128,7 +4101,7 @@ void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
         * So here we should only check item pointers, not item data.
         */
        if (btrfs_header_level(buf) == 0 &&
-           btrfs_check_leaf_relaxed(fs_info, buf)) {
+           btrfs_check_leaf_relaxed(buf)) {
                btrfs_print_leaf(buf);
                ASSERT(0);
        }
@@ -4171,10 +4144,7 @@ void btrfs_btree_balance_dirty_nodelay(struct btrfs_fs_info *fs_info)
 int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid, int level,
                      struct btrfs_key *first_key)
 {
-       struct btrfs_root *root = BTRFS_I(buf->pages[0]->mapping->host)->root;
-       struct btrfs_fs_info *fs_info = root->fs_info;
-
-       return btree_read_extent_buffer_pages(fs_info, buf, parent_transid,
+       return btree_read_extent_buffer_pages(buf, parent_transid,
                                              level, first_key);
 }
 
@@ -4498,10 +4468,17 @@ void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *cur_trans,
 void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
                                   struct btrfs_fs_info *fs_info)
 {
+       struct btrfs_device *dev, *tmp;
+
        btrfs_cleanup_dirty_bgs(cur_trans, fs_info);
        ASSERT(list_empty(&cur_trans->dirty_bgs));
        ASSERT(list_empty(&cur_trans->io_bgs));
 
+       list_for_each_entry_safe(dev, tmp, &cur_trans->dev_update_list,
+                                post_commit_list) {
+               list_del_init(&dev->post_commit_list);
+       }
+
        btrfs_destroy_delayed_refs(cur_trans, fs_info);
 
        cur_trans->state = TRANS_STATE_COMMIT_START;