aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-01-24 16:13:08 -0500
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:03:59 -0400
commitd1310b2e0cd98eb1348553e69b73827b436dca7b (patch)
treef55e9c380df0f3a7e9fb792b2308b52b632b90aa /fs/btrfs/extent-tree.c
parent5f56406aabdf5444d040c5955effc665b1d0dbaf (diff)
Btrfs: Split the extent_map code into two parts
There is now extent_map for mapping offsets in the file to disk and extent_io for state tracking, IO submission and extent_bufers. The new extent_map code shifts from [start,end] pairs to [start,len], and pushes the locking out into the caller. This allows a few performance optimizations and is easier to use. A number of extent_map usage bugs were fixed, mostly with failing to remove extent_map entries when changing the file. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index b69a46691a96..1cf125ab7822 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -63,7 +63,7 @@ static int cache_block_group(struct btrfs_root *root,
63 int ret; 63 int ret;
64 struct btrfs_key key; 64 struct btrfs_key key;
65 struct extent_buffer *leaf; 65 struct extent_buffer *leaf;
66 struct extent_map_tree *free_space_cache; 66 struct extent_io_tree *free_space_cache;
67 int slot; 67 int slot;
68 u64 last = 0; 68 u64 last = 0;
69 u64 hole_size; 69 u64 hole_size;
@@ -158,7 +158,7 @@ struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
158 btrfs_fs_info *info, 158 btrfs_fs_info *info,
159 u64 bytenr) 159 u64 bytenr)
160{ 160{
161 struct extent_map_tree *block_group_cache; 161 struct extent_io_tree *block_group_cache;
162 struct btrfs_block_group_cache *block_group = NULL; 162 struct btrfs_block_group_cache *block_group = NULL;
163 u64 ptr; 163 u64 ptr;
164 u64 start; 164 u64 start;
@@ -281,7 +281,7 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
281 int data, int owner) 281 int data, int owner)
282{ 282{
283 struct btrfs_block_group_cache *cache; 283 struct btrfs_block_group_cache *cache;
284 struct extent_map_tree *block_group_cache; 284 struct extent_io_tree *block_group_cache;
285 struct btrfs_block_group_cache *found_group = NULL; 285 struct btrfs_block_group_cache *found_group = NULL;
286 struct btrfs_fs_info *info = root->fs_info; 286 struct btrfs_fs_info *info = root->fs_info;
287 u64 used; 287 u64 used;
@@ -951,7 +951,7 @@ fail:
951int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, 951int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
952 struct btrfs_root *root) 952 struct btrfs_root *root)
953{ 953{
954 struct extent_map_tree *block_group_cache; 954 struct extent_io_tree *block_group_cache;
955 struct btrfs_block_group_cache *cache; 955 struct btrfs_block_group_cache *cache;
956 int ret; 956 int ret;
957 int err = 0; 957 int err = 0;
@@ -1107,12 +1107,12 @@ static int update_pinned_extents(struct btrfs_root *root,
1107 return 0; 1107 return 0;
1108} 1108}
1109 1109
1110int btrfs_copy_pinned(struct btrfs_root *root, struct extent_map_tree *copy) 1110int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy)
1111{ 1111{
1112 u64 last = 0; 1112 u64 last = 0;
1113 u64 start; 1113 u64 start;
1114 u64 end; 1114 u64 end;
1115 struct extent_map_tree *pinned_extents = &root->fs_info->pinned_extents; 1115 struct extent_io_tree *pinned_extents = &root->fs_info->pinned_extents;
1116 int ret; 1116 int ret;
1117 1117
1118 while(1) { 1118 while(1) {
@@ -1128,12 +1128,12 @@ int btrfs_copy_pinned(struct btrfs_root *root, struct extent_map_tree *copy)
1128 1128
1129int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, 1129int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1130 struct btrfs_root *root, 1130 struct btrfs_root *root,
1131 struct extent_map_tree *unpin) 1131 struct extent_io_tree *unpin)
1132{ 1132{
1133 u64 start; 1133 u64 start;
1134 u64 end; 1134 u64 end;
1135 int ret; 1135 int ret;
1136 struct extent_map_tree *free_space_cache; 1136 struct extent_io_tree *free_space_cache;
1137 free_space_cache = &root->fs_info->free_space_cache; 1137 free_space_cache = &root->fs_info->free_space_cache;
1138 1138
1139 while(1) { 1139 while(1) {
@@ -1329,8 +1329,8 @@ static int del_pending_extents(struct btrfs_trans_handle *trans, struct
1329 int err = 0; 1329 int err = 0;
1330 u64 start; 1330 u64 start;
1331 u64 end; 1331 u64 end;
1332 struct extent_map_tree *pending_del; 1332 struct extent_io_tree *pending_del;
1333 struct extent_map_tree *pinned_extents; 1333 struct extent_io_tree *pinned_extents;
1334 1334
1335 pending_del = &extent_root->fs_info->pending_del; 1335 pending_del = &extent_root->fs_info->pending_del;
1336 pinned_extents = &extent_root->fs_info->pinned_extents; 1336 pinned_extents = &extent_root->fs_info->pinned_extents;
@@ -1802,7 +1802,7 @@ struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1802 1802
1803 set_extent_dirty(&trans->transaction->dirty_pages, buf->start, 1803 set_extent_dirty(&trans->transaction->dirty_pages, buf->start,
1804 buf->start + buf->len - 1, GFP_NOFS); 1804 buf->start + buf->len - 1, GFP_NOFS);
1805 set_extent_bits(&BTRFS_I(root->fs_info->btree_inode)->extent_tree, 1805 set_extent_bits(&BTRFS_I(root->fs_info->btree_inode)->io_tree,
1806 buf->start, buf->start + buf->len - 1, 1806 buf->start, buf->start + buf->len - 1,
1807 EXTENT_CSUM, GFP_NOFS); 1807 EXTENT_CSUM, GFP_NOFS);
1808 buf->flags |= EXTENT_CSUM; 1808 buf->flags |= EXTENT_CSUM;
@@ -2166,7 +2166,7 @@ static int noinline relocate_inode_pages(struct inode *inode, u64 start,
2166 unsigned long i; 2166 unsigned long i;
2167 struct page *page; 2167 struct page *page;
2168 struct btrfs_root *root = BTRFS_I(inode)->root; 2168 struct btrfs_root *root = BTRFS_I(inode)->root;
2169 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 2169 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
2170 struct file_ra_state *ra; 2170 struct file_ra_state *ra;
2171 2171
2172 ra = kzalloc(sizeof(*ra), GFP_NOFS); 2172 ra = kzalloc(sizeof(*ra), GFP_NOFS);
@@ -2195,15 +2195,14 @@ static int noinline relocate_inode_pages(struct inode *inode, u64 start,
2195 page_start = (u64)page->index << PAGE_CACHE_SHIFT; 2195 page_start = (u64)page->index << PAGE_CACHE_SHIFT;
2196 page_end = page_start + PAGE_CACHE_SIZE - 1; 2196 page_end = page_start + PAGE_CACHE_SIZE - 1;
2197 2197
2198 lock_extent(em_tree, page_start, page_end, GFP_NOFS); 2198 lock_extent(io_tree, page_start, page_end, GFP_NOFS);
2199 2199
2200 delalloc_start = page_start; 2200 delalloc_start = page_start;
2201 existing_delalloc = 2201 existing_delalloc = count_range_bits(io_tree,
2202 count_range_bits(&BTRFS_I(inode)->extent_tree, 2202 &delalloc_start, page_end,
2203 &delalloc_start, page_end, 2203 PAGE_CACHE_SIZE, EXTENT_DELALLOC);
2204 PAGE_CACHE_SIZE, EXTENT_DELALLOC);
2205 2204
2206 set_extent_delalloc(em_tree, page_start, 2205 set_extent_delalloc(io_tree, page_start,
2207 page_end, GFP_NOFS); 2206 page_end, GFP_NOFS);
2208 2207
2209 spin_lock(&root->fs_info->delalloc_lock); 2208 spin_lock(&root->fs_info->delalloc_lock);
@@ -2211,7 +2210,7 @@ static int noinline relocate_inode_pages(struct inode *inode, u64 start,
2211 existing_delalloc; 2210 existing_delalloc;
2212 spin_unlock(&root->fs_info->delalloc_lock); 2211 spin_unlock(&root->fs_info->delalloc_lock);
2213 2212
2214 unlock_extent(em_tree, page_start, page_end, GFP_NOFS); 2213 unlock_extent(io_tree, page_start, page_end, GFP_NOFS);
2215 set_page_dirty(page); 2214 set_page_dirty(page);
2216 unlock_page(page); 2215 unlock_page(page);
2217 page_cache_release(page); 2216 page_cache_release(page);
@@ -2379,7 +2378,7 @@ int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size)
2379 u64 cur_byte; 2378 u64 cur_byte;
2380 u64 total_found; 2379 u64 total_found;
2381 struct btrfs_fs_info *info = root->fs_info; 2380 struct btrfs_fs_info *info = root->fs_info;
2382 struct extent_map_tree *block_group_cache; 2381 struct extent_io_tree *block_group_cache;
2383 struct btrfs_key key; 2382 struct btrfs_key key;
2384 struct btrfs_key found_key; 2383 struct btrfs_key found_key;
2385 struct extent_buffer *leaf; 2384 struct extent_buffer *leaf;
@@ -2561,7 +2560,7 @@ int btrfs_grow_extent_tree(struct btrfs_trans_handle *trans,
2561 struct btrfs_block_group_cache *cache; 2560 struct btrfs_block_group_cache *cache;
2562 struct btrfs_block_group_item *item; 2561 struct btrfs_block_group_item *item;
2563 struct btrfs_fs_info *info = root->fs_info; 2562 struct btrfs_fs_info *info = root->fs_info;
2564 struct extent_map_tree *block_group_cache; 2563 struct extent_io_tree *block_group_cache;
2565 struct btrfs_key key; 2564 struct btrfs_key key;
2566 struct extent_buffer *leaf; 2565 struct extent_buffer *leaf;
2567 int ret; 2566 int ret;
@@ -2645,7 +2644,7 @@ int btrfs_read_block_groups(struct btrfs_root *root)
2645 int bit; 2644 int bit;
2646 struct btrfs_block_group_cache *cache; 2645 struct btrfs_block_group_cache *cache;
2647 struct btrfs_fs_info *info = root->fs_info; 2646 struct btrfs_fs_info *info = root->fs_info;
2648 struct extent_map_tree *block_group_cache; 2647 struct extent_io_tree *block_group_cache;
2649 struct btrfs_key key; 2648 struct btrfs_key key;
2650 struct btrfs_key found_key; 2649 struct btrfs_key found_key;
2651 struct extent_buffer *leaf; 2650 struct extent_buffer *leaf;