extent-tree.c (e18e4809b10e6c9efb5fe10c1ddcb4ebb690d517) extent-tree.c (d1310b2e0cd98eb1348553e69b73827b436dca7b)
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 49 unchanged lines hidden (view full) ---

58
59static int cache_block_group(struct btrfs_root *root,
60 struct btrfs_block_group_cache *block_group)
61{
62 struct btrfs_path *path;
63 int ret;
64 struct btrfs_key key;
65 struct extent_buffer *leaf;
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 49 unchanged lines hidden (view full) ---

58
59static int cache_block_group(struct btrfs_root *root,
60 struct btrfs_block_group_cache *block_group)
61{
62 struct btrfs_path *path;
63 int ret;
64 struct btrfs_key key;
65 struct extent_buffer *leaf;
66 struct extent_map_tree *free_space_cache;
66 struct extent_io_tree *free_space_cache;
67 int slot;
68 u64 last = 0;
69 u64 hole_size;
70 u64 first_free;
71 int found = 0;
72
73 if (!block_group)
74 return 0;

--- 78 unchanged lines hidden (view full) ---

153 btrfs_free_path(path);
154 return 0;
155}
156
157struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
158 btrfs_fs_info *info,
159 u64 bytenr)
160{
67 int slot;
68 u64 last = 0;
69 u64 hole_size;
70 u64 first_free;
71 int found = 0;
72
73 if (!block_group)
74 return 0;

--- 78 unchanged lines hidden (view full) ---

153 btrfs_free_path(path);
154 return 0;
155}
156
157struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
158 btrfs_fs_info *info,
159 u64 bytenr)
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;
163 u64 ptr;
164 u64 start;
165 u64 end;
166 int ret;
167
168 block_group_cache = &info->block_group_cache;
169 ret = find_first_extent_bit(block_group_cache,

--- 106 unchanged lines hidden (view full) ---

276}
277
278struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
279 struct btrfs_block_group_cache
280 *hint, u64 search_start,
281 int data, int owner)
282{
283 struct btrfs_block_group_cache *cache;
162 struct btrfs_block_group_cache *block_group = NULL;
163 u64 ptr;
164 u64 start;
165 u64 end;
166 int ret;
167
168 block_group_cache = &info->block_group_cache;
169 ret = find_first_extent_bit(block_group_cache,

--- 106 unchanged lines hidden (view full) ---

276}
277
278struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
279 struct btrfs_block_group_cache
280 *hint, u64 search_start,
281 int data, int owner)
282{
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;
286 struct btrfs_fs_info *info = root->fs_info;
287 u64 used;
288 u64 last = 0;
289 u64 hint_last;
290 u64 start;
291 u64 end;
292 u64 free_check;

--- 653 unchanged lines hidden (view full) ---

946 return pending_ret;
947 return 0;
948
949}
950
951int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
952 struct btrfs_root *root)
953{
285 struct btrfs_block_group_cache *found_group = NULL;
286 struct btrfs_fs_info *info = root->fs_info;
287 u64 used;
288 u64 last = 0;
289 u64 hint_last;
290 u64 start;
291 u64 end;
292 u64 free_check;

--- 653 unchanged lines hidden (view full) ---

946 return pending_ret;
947 return 0;
948
949}
950
951int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
952 struct btrfs_root *root)
953{
954 struct extent_map_tree *block_group_cache;
954 struct extent_io_tree *block_group_cache;
955 struct btrfs_block_group_cache *cache;
956 int ret;
957 int err = 0;
958 int werr = 0;
959 struct btrfs_path *path;
960 u64 last = 0;
961 u64 start;
962 u64 end;

--- 139 unchanged lines hidden (view full) ---

1102 fs_info->total_pinned -= len;
1103 }
1104 bytenr += len;
1105 num -= len;
1106 }
1107 return 0;
1108}
1109
955 struct btrfs_block_group_cache *cache;
956 int ret;
957 int err = 0;
958 int werr = 0;
959 struct btrfs_path *path;
960 u64 last = 0;
961 u64 start;
962 u64 end;

--- 139 unchanged lines hidden (view full) ---

1102 fs_info->total_pinned -= len;
1103 }
1104 bytenr += len;
1105 num -= len;
1106 }
1107 return 0;
1108}
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{
1112 u64 last = 0;
1113 u64 start;
1114 u64 end;
1111{
1112 u64 last = 0;
1113 u64 start;
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;
1117
1118 while(1) {
1119 ret = find_first_extent_bit(pinned_extents, last,
1120 &start, &end, EXTENT_DIRTY);
1121 if (ret)
1122 break;
1123 set_extent_dirty(copy, start, end, GFP_NOFS);
1124 last = end + 1;
1125 }
1126 return 0;
1127}
1128
1129int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1130 struct btrfs_root *root,
1116 int ret;
1117
1118 while(1) {
1119 ret = find_first_extent_bit(pinned_extents, last,
1120 &start, &end, EXTENT_DIRTY);
1121 if (ret)
1122 break;
1123 set_extent_dirty(copy, start, end, GFP_NOFS);
1124 last = end + 1;
1125 }
1126 return 0;
1127}
1128
1129int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1130 struct btrfs_root *root,
1131 struct extent_map_tree *unpin)
1131 struct extent_io_tree *unpin)
1132{
1133 u64 start;
1134 u64 end;
1135 int ret;
1132{
1133 u64 start;
1134 u64 end;
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;
1138
1139 while(1) {
1140 ret = find_first_extent_bit(unpin, 0, &start, &end,
1141 EXTENT_DIRTY);
1142 if (ret)
1143 break;
1144 update_pinned_extents(root, start, end + 1 - start, 0);

--- 179 unchanged lines hidden (view full) ---

1324 */
1325static int del_pending_extents(struct btrfs_trans_handle *trans, struct
1326 btrfs_root *extent_root)
1327{
1328 int ret;
1329 int err = 0;
1330 u64 start;
1331 u64 end;
1137 free_space_cache = &root->fs_info->free_space_cache;
1138
1139 while(1) {
1140 ret = find_first_extent_bit(unpin, 0, &start, &end,
1141 EXTENT_DIRTY);
1142 if (ret)
1143 break;
1144 update_pinned_extents(root, start, end + 1 - start, 0);

--- 179 unchanged lines hidden (view full) ---

1324 */
1325static int del_pending_extents(struct btrfs_trans_handle *trans, struct
1326 btrfs_root *extent_root)
1327{
1328 int ret;
1329 int err = 0;
1330 u64 start;
1331 u64 end;
1332 struct extent_map_tree *pending_del;
1333 struct extent_map_tree *pinned_extents;
1332 struct extent_io_tree *pending_del;
1333 struct extent_io_tree *pinned_extents;
1334
1335 pending_del = &extent_root->fs_info->pending_del;
1336 pinned_extents = &extent_root->fs_info->pinned_extents;
1337
1338 while(1) {
1339 ret = find_first_extent_bit(pending_del, 0, &start, &end,
1340 EXTENT_LOCKED);
1341 if (ret)

--- 455 unchanged lines hidden (view full) ---

1797
1798 if (PageDirty(buf->first_page)) {
1799 printk("page %lu dirty\n", buf->first_page->index);
1800 WARN_ON(1);
1801 }
1802
1803 set_extent_dirty(&trans->transaction->dirty_pages, buf->start,
1804 buf->start + buf->len - 1, GFP_NOFS);
1334
1335 pending_del = &extent_root->fs_info->pending_del;
1336 pinned_extents = &extent_root->fs_info->pinned_extents;
1337
1338 while(1) {
1339 ret = find_first_extent_bit(pending_del, 0, &start, &end,
1340 EXTENT_LOCKED);
1341 if (ret)

--- 455 unchanged lines hidden (view full) ---

1797
1798 if (PageDirty(buf->first_page)) {
1799 printk("page %lu dirty\n", buf->first_page->index);
1800 WARN_ON(1);
1801 }
1802
1803 set_extent_dirty(&trans->transaction->dirty_pages, buf->start,
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,
1807 EXTENT_CSUM, GFP_NOFS);
1808 buf->flags |= EXTENT_CSUM;
1809 if (!btrfs_test_opt(root, SSD))
1810 btrfs_set_buffer_defrag(buf);
1811 trans->blocks_used++;
1812 return buf;
1813}

--- 347 unchanged lines hidden (view full) ---

2161 u64 page_start;
2162 u64 page_end;
2163 u64 delalloc_start;
2164 u64 existing_delalloc;
2165 unsigned long last_index;
2166 unsigned long i;
2167 struct page *page;
2168 struct btrfs_root *root = BTRFS_I(inode)->root;
1806 buf->start, buf->start + buf->len - 1,
1807 EXTENT_CSUM, GFP_NOFS);
1808 buf->flags |= EXTENT_CSUM;
1809 if (!btrfs_test_opt(root, SSD))
1810 btrfs_set_buffer_defrag(buf);
1811 trans->blocks_used++;
1812 return buf;
1813}

--- 347 unchanged lines hidden (view full) ---

2161 u64 page_start;
2162 u64 page_end;
2163 u64 delalloc_start;
2164 u64 existing_delalloc;
2165 unsigned long last_index;
2166 unsigned long i;
2167 struct page *page;
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;
2171
2172 ra = kzalloc(sizeof(*ra), GFP_NOFS);
2173
2174 mutex_lock(&inode->i_mutex);
2175 i = start >> PAGE_CACHE_SHIFT;
2176 last_index = (start + len - 1) >> PAGE_CACHE_SHIFT;
2177

--- 12 unchanged lines hidden (view full) ---

2190 unlock_page(page);
2191 page_cache_release(page);
2192 goto out_unlock;
2193 }
2194 }
2195 page_start = (u64)page->index << PAGE_CACHE_SHIFT;
2196 page_end = page_start + PAGE_CACHE_SIZE - 1;
2197
2170 struct file_ra_state *ra;
2171
2172 ra = kzalloc(sizeof(*ra), GFP_NOFS);
2173
2174 mutex_lock(&inode->i_mutex);
2175 i = start >> PAGE_CACHE_SHIFT;
2176 last_index = (start + len - 1) >> PAGE_CACHE_SHIFT;
2177

--- 12 unchanged lines hidden (view full) ---

2190 unlock_page(page);
2191 page_cache_release(page);
2192 goto out_unlock;
2193 }
2194 }
2195 page_start = (u64)page->index << PAGE_CACHE_SHIFT;
2196 page_end = page_start + PAGE_CACHE_SIZE - 1;
2197
2198 lock_extent(em_tree, page_start, page_end, GFP_NOFS);
2198 lock_extent(io_tree, page_start, page_end, GFP_NOFS);
2199
2200 delalloc_start = page_start;
2199
2200 delalloc_start = page_start;
2201 existing_delalloc =
2202 count_range_bits(&BTRFS_I(inode)->extent_tree,
2203 &delalloc_start, page_end,
2204 PAGE_CACHE_SIZE, EXTENT_DELALLOC);
2201 existing_delalloc = count_range_bits(io_tree,
2202 &delalloc_start, page_end,
2203 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);
2208
2209 spin_lock(&root->fs_info->delalloc_lock);
2210 root->fs_info->delalloc_bytes += PAGE_CACHE_SIZE -
2211 existing_delalloc;
2212 spin_unlock(&root->fs_info->delalloc_lock);
2213
2206 page_end, GFP_NOFS);
2207
2208 spin_lock(&root->fs_info->delalloc_lock);
2209 root->fs_info->delalloc_bytes += PAGE_CACHE_SIZE -
2210 existing_delalloc;
2211 spin_unlock(&root->fs_info->delalloc_lock);
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);
2216 unlock_page(page);
2217 page_cache_release(page);
2218 }
2219
2220out_unlock:
2221 mutex_unlock(&inode->i_mutex);
2222 return 0;

--- 151 unchanged lines hidden (view full) ---

2374int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size)
2375{
2376 struct btrfs_trans_handle *trans;
2377 struct btrfs_root *tree_root = root->fs_info->tree_root;
2378 struct btrfs_path *path;
2379 u64 cur_byte;
2380 u64 total_found;
2381 struct btrfs_fs_info *info = root->fs_info;
2214 set_page_dirty(page);
2215 unlock_page(page);
2216 page_cache_release(page);
2217 }
2218
2219out_unlock:
2220 mutex_unlock(&inode->i_mutex);
2221 return 0;

--- 151 unchanged lines hidden (view full) ---

2373int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size)
2374{
2375 struct btrfs_trans_handle *trans;
2376 struct btrfs_root *tree_root = root->fs_info->tree_root;
2377 struct btrfs_path *path;
2378 u64 cur_byte;
2379 u64 total_found;
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;
2384 struct btrfs_key found_key;
2385 struct extent_buffer *leaf;
2386 u32 nritems;
2387 int ret;
2388 int progress = 0;
2389
2390 btrfs_set_super_total_bytes(&info->super_copy, new_size);

--- 165 unchanged lines hidden (view full) ---

2556 struct btrfs_path *path;
2557 u64 nr = 0;
2558 u64 cur_byte;
2559 u64 old_size;
2560 unsigned long rem;
2561 struct btrfs_block_group_cache *cache;
2562 struct btrfs_block_group_item *item;
2563 struct btrfs_fs_info *info = root->fs_info;
2382 struct btrfs_key key;
2383 struct btrfs_key found_key;
2384 struct extent_buffer *leaf;
2385 u32 nritems;
2386 int ret;
2387 int progress = 0;
2388
2389 btrfs_set_super_total_bytes(&info->super_copy, new_size);

--- 165 unchanged lines hidden (view full) ---

2555 struct btrfs_path *path;
2556 u64 nr = 0;
2557 u64 cur_byte;
2558 u64 old_size;
2559 unsigned long rem;
2560 struct btrfs_block_group_cache *cache;
2561 struct btrfs_block_group_item *item;
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;
2566 struct extent_buffer *leaf;
2567 int ret;
2568 int bit;
2569
2570 old_size = btrfs_super_total_bytes(&info->super_copy);
2571 block_group_cache = &info->block_group_cache;
2572

--- 67 unchanged lines hidden (view full) ---

2640int btrfs_read_block_groups(struct btrfs_root *root)
2641{
2642 struct btrfs_path *path;
2643 int ret;
2644 int err = 0;
2645 int bit;
2646 struct btrfs_block_group_cache *cache;
2647 struct btrfs_fs_info *info = root->fs_info;
2564 struct btrfs_key key;
2565 struct extent_buffer *leaf;
2566 int ret;
2567 int bit;
2568
2569 old_size = btrfs_super_total_bytes(&info->super_copy);
2570 block_group_cache = &info->block_group_cache;
2571

--- 67 unchanged lines hidden (view full) ---

2639int btrfs_read_block_groups(struct btrfs_root *root)
2640{
2641 struct btrfs_path *path;
2642 int ret;
2643 int err = 0;
2644 int bit;
2645 struct btrfs_block_group_cache *cache;
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;
2650 struct btrfs_key found_key;
2651 struct extent_buffer *leaf;
2652
2653 block_group_cache = &info->block_group_cache;
2654
2655 root = info->extent_root;
2656 key.objectid = 0;

--- 57 unchanged lines hidden ---
2648 struct btrfs_key key;
2649 struct btrfs_key found_key;
2650 struct extent_buffer *leaf;
2651
2652 block_group_cache = &info->block_group_cache;
2653
2654 root = info->extent_root;
2655 key.objectid = 0;

--- 57 unchanged lines hidden ---