Btrfs: Back port to 2.6.18-el kernels
[deliverable/linux.git] / fs / btrfs / disk-io.c
index 6c8533fba7c952bbca15166cb2378af8e3e51e0f..ebb2db624fddab4c1ffce160322b78e9e0a01c81 100644 (file)
@@ -210,6 +210,24 @@ static int btree_writepages(struct address_space *mapping,
 {
        struct extent_map_tree *tree;
        tree = &BTRFS_I(mapping->host)->extent_tree;
+       if (wbc->sync_mode == WB_SYNC_NONE) {
+               u64 num_dirty;
+               u64 start = 0;
+               unsigned long thresh = 96 * 1024 * 1024;
+
+               if (wbc->for_kupdate)
+                       return 0;
+
+               if (current_is_pdflush()) {
+                       thresh = 96 * 1024 * 1024;
+               } else {
+                       thresh = 8 * 1024 * 1024;
+               }
+               num_dirty = count_range_bits(tree, &start, thresh, EXTENT_DIRTY);
+               if (num_dirty < thresh) {
+                       return 0;
+               }
+       }
        return extent_writepages(tree, mapping, btree_get_extent, wbc);
 }
 
@@ -337,7 +355,7 @@ int wait_on_tree_block_writeback(struct btrfs_root *root,
 }
 
 static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
-                       struct btrfs_root *root,
+                       u32 stripesize, struct btrfs_root *root,
                        struct btrfs_fs_info *fs_info,
                        u64 objectid)
 {
@@ -347,6 +365,7 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
        root->sectorsize = sectorsize;
        root->nodesize = nodesize;
        root->leafsize = leafsize;
+       root->stripesize = stripesize;
        root->ref_cows = 0;
        root->fs_info = fs_info;
        root->objectid = objectid;
@@ -375,7 +394,8 @@ static int find_and_setup_root(struct btrfs_root *tree_root,
        u32 blocksize;
 
        __setup_root(tree_root->nodesize, tree_root->leafsize,
-                    tree_root->sectorsize, root, fs_info, objectid);
+                    tree_root->sectorsize, tree_root->stripesize,
+                    root, fs_info, objectid);
        ret = btrfs_find_last_root(tree_root, objectid,
                                   &root->root_item, &root->root_key);
        BUG_ON(ret);
@@ -412,8 +432,8 @@ struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_fs_info *fs_info,
        }
 
        __setup_root(tree_root->nodesize, tree_root->leafsize,
-                    tree_root->sectorsize, root, fs_info,
-                    location->objectid);
+                    tree_root->sectorsize, tree_root->stripesize,
+                    root, fs_info, location->objectid);
 
        path = btrfs_alloc_path();
        BUG_ON(!path);
@@ -519,6 +539,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
        u32 nodesize;
        u32 leafsize;
        u32 blocksize;
+       u32 stripesize;
        struct btrfs_root *extent_root = kmalloc(sizeof(struct btrfs_root),
                                                 GFP_NOFS);
        struct btrfs_root *tree_root = kmalloc(sizeof(struct btrfs_root),
@@ -547,6 +568,8 @@ struct btrfs_root *open_ctree(struct super_block *sb)
        fs_info->tree_root = tree_root;
        fs_info->extent_root = extent_root;
        fs_info->sb = sb;
+       fs_info->mount_opt = 0;
+       fs_info->max_extent = (u64)-1;
        fs_info->btree_inode = new_inode(sb);
        fs_info->btree_inode->i_ino = 1;
        fs_info->btree_inode->i_nlink = 1;
@@ -569,8 +592,12 @@ struct btrfs_root *open_ctree(struct super_block *sb)
                             fs_info->btree_inode->i_mapping, GFP_NOFS);
        fs_info->do_barriers = 1;
        fs_info->closing = 0;
-
+       fs_info->total_pinned = 0;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
+       INIT_WORK(&fs_info->trans_work, btrfs_transaction_cleaner, fs_info);
+#else
        INIT_DELAYED_WORK(&fs_info->trans_work, btrfs_transaction_cleaner);
+#endif
        BTRFS_I(fs_info->btree_inode)->root = tree_root;
        memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
               sizeof(struct btrfs_key));
@@ -588,7 +615,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
                goto fail_iput;
        }
 #endif
-       __setup_root(512, 512, 512, tree_root,
+       __setup_root(512, 512, 512, 512, tree_root,
                     fs_info, BTRFS_ROOT_TREE_OBJECTID);
 
        fs_info->sb_buffer = read_tree_block(tree_root,
@@ -611,9 +638,11 @@ struct btrfs_root *open_ctree(struct super_block *sb)
        nodesize = btrfs_super_nodesize(disk_super);
        leafsize = btrfs_super_leafsize(disk_super);
        sectorsize = btrfs_super_sectorsize(disk_super);
+       stripesize = btrfs_super_stripesize(disk_super);
        tree_root->nodesize = nodesize;
        tree_root->leafsize = leafsize;
        tree_root->sectorsize = sectorsize;
+       tree_root->stripesize = stripesize;
        sb_set_blocksize(sb, sectorsize);
 
        i_size_write(fs_info->btree_inode,
@@ -740,8 +769,18 @@ int close_ctree(struct btrfs_root *root)
 
        btrfs_free_block_groups(root->fs_info);
        del_fs_roots(fs_info);
+
+       filemap_write_and_wait(fs_info->btree_inode->i_mapping);
+
+       extent_map_tree_empty_lru(&fs_info->free_space_cache);
+       extent_map_tree_empty_lru(&fs_info->block_group_cache);
+       extent_map_tree_empty_lru(&fs_info->pinned_extents);
+       extent_map_tree_empty_lru(&fs_info->pending_del);
+       extent_map_tree_empty_lru(&fs_info->extent_ins);
        extent_map_tree_empty_lru(&BTRFS_I(fs_info->btree_inode)->extent_tree);
+
        truncate_inode_pages(fs_info->btree_inode->i_mapping, 0);
+
        iput(fs_info->btree_inode);
 #if 0
        while(!list_empty(&fs_info->hashers)) {
This page took 0.027303 seconds and 5 git commands to generate.