diff options
author | Chris Mason <chris.mason@oracle.com> | 2011-05-22 12:33:42 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2011-05-22 12:33:42 -0400 |
commit | 945d8962ceee6bb273365d0bdf42f763225b290f (patch) | |
tree | 43f5617022c7c947c3c63664e49eb9575ab82f2f | |
parent | 0d0ca30f180906224be6279788f2b202cfd959d8 (diff) | |
parent | 4ea028859bbdad34b84c9951fbb832ae10c6a96c (diff) |
Merge branch 'cleanups' of git://repo.or.cz/linux-2.6/btrfs-unstable into inode_numbers
Conflicts:
fs/btrfs/extent-tree.c
fs/btrfs/free-space-cache.c
fs/btrfs/inode.c
fs/btrfs/tree-log.c
Signed-off-by: Chris Mason <chris.mason@oracle.com>
38 files changed, 295 insertions, 3234 deletions
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 44ea5b92e1ba..f66fc9959733 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c | |||
@@ -288,7 +288,7 @@ int btrfs_acl_chmod(struct inode *inode) | |||
288 | return 0; | 288 | return 0; |
289 | 289 | ||
290 | acl = btrfs_get_acl(inode, ACL_TYPE_ACCESS); | 290 | acl = btrfs_get_acl(inode, ACL_TYPE_ACCESS); |
291 | if (IS_ERR(acl) || !acl) | 291 | if (IS_ERR_OR_NULL(acl)) |
292 | return PTR_ERR(acl); | 292 | return PTR_ERR(acl); |
293 | 293 | ||
294 | clone = posix_acl_clone(acl, GFP_KERNEL); | 294 | clone = posix_acl_clone(acl, GFP_KERNEL); |
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 369d5068ac7a..bfe42b03eaf9 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c | |||
@@ -333,7 +333,7 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start, | |||
333 | struct compressed_bio *cb; | 333 | struct compressed_bio *cb; |
334 | unsigned long bytes_left; | 334 | unsigned long bytes_left; |
335 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; | 335 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; |
336 | int page_index = 0; | 336 | int pg_index = 0; |
337 | struct page *page; | 337 | struct page *page; |
338 | u64 first_byte = disk_start; | 338 | u64 first_byte = disk_start; |
339 | struct block_device *bdev; | 339 | struct block_device *bdev; |
@@ -367,8 +367,8 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start, | |||
367 | 367 | ||
368 | /* create and submit bios for the compressed pages */ | 368 | /* create and submit bios for the compressed pages */ |
369 | bytes_left = compressed_len; | 369 | bytes_left = compressed_len; |
370 | for (page_index = 0; page_index < cb->nr_pages; page_index++) { | 370 | for (pg_index = 0; pg_index < cb->nr_pages; pg_index++) { |
371 | page = compressed_pages[page_index]; | 371 | page = compressed_pages[pg_index]; |
372 | page->mapping = inode->i_mapping; | 372 | page->mapping = inode->i_mapping; |
373 | if (bio->bi_size) | 373 | if (bio->bi_size) |
374 | ret = io_tree->ops->merge_bio_hook(page, 0, | 374 | ret = io_tree->ops->merge_bio_hook(page, 0, |
@@ -433,7 +433,7 @@ static noinline int add_ra_bio_pages(struct inode *inode, | |||
433 | struct compressed_bio *cb) | 433 | struct compressed_bio *cb) |
434 | { | 434 | { |
435 | unsigned long end_index; | 435 | unsigned long end_index; |
436 | unsigned long page_index; | 436 | unsigned long pg_index; |
437 | u64 last_offset; | 437 | u64 last_offset; |
438 | u64 isize = i_size_read(inode); | 438 | u64 isize = i_size_read(inode); |
439 | int ret; | 439 | int ret; |
@@ -457,13 +457,13 @@ static noinline int add_ra_bio_pages(struct inode *inode, | |||
457 | end_index = (i_size_read(inode) - 1) >> PAGE_CACHE_SHIFT; | 457 | end_index = (i_size_read(inode) - 1) >> PAGE_CACHE_SHIFT; |
458 | 458 | ||
459 | while (last_offset < compressed_end) { | 459 | while (last_offset < compressed_end) { |
460 | page_index = last_offset >> PAGE_CACHE_SHIFT; | 460 | pg_index = last_offset >> PAGE_CACHE_SHIFT; |
461 | 461 | ||
462 | if (page_index > end_index) | 462 | if (pg_index > end_index) |
463 | break; | 463 | break; |
464 | 464 | ||
465 | rcu_read_lock(); | 465 | rcu_read_lock(); |
466 | page = radix_tree_lookup(&mapping->page_tree, page_index); | 466 | page = radix_tree_lookup(&mapping->page_tree, pg_index); |
467 | rcu_read_unlock(); | 467 | rcu_read_unlock(); |
468 | if (page) { | 468 | if (page) { |
469 | misses++; | 469 | misses++; |
@@ -477,7 +477,7 @@ static noinline int add_ra_bio_pages(struct inode *inode, | |||
477 | if (!page) | 477 | if (!page) |
478 | break; | 478 | break; |
479 | 479 | ||
480 | if (add_to_page_cache_lru(page, mapping, page_index, | 480 | if (add_to_page_cache_lru(page, mapping, pg_index, |
481 | GFP_NOFS)) { | 481 | GFP_NOFS)) { |
482 | page_cache_release(page); | 482 | page_cache_release(page); |
483 | goto next; | 483 | goto next; |
@@ -561,7 +561,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, | |||
561 | unsigned long uncompressed_len = bio->bi_vcnt * PAGE_CACHE_SIZE; | 561 | unsigned long uncompressed_len = bio->bi_vcnt * PAGE_CACHE_SIZE; |
562 | unsigned long compressed_len; | 562 | unsigned long compressed_len; |
563 | unsigned long nr_pages; | 563 | unsigned long nr_pages; |
564 | unsigned long page_index; | 564 | unsigned long pg_index; |
565 | struct page *page; | 565 | struct page *page; |
566 | struct block_device *bdev; | 566 | struct block_device *bdev; |
567 | struct bio *comp_bio; | 567 | struct bio *comp_bio; |
@@ -614,10 +614,10 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, | |||
614 | 614 | ||
615 | bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; | 615 | bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; |
616 | 616 | ||
617 | for (page_index = 0; page_index < nr_pages; page_index++) { | 617 | for (pg_index = 0; pg_index < nr_pages; pg_index++) { |
618 | cb->compressed_pages[page_index] = alloc_page(GFP_NOFS | | 618 | cb->compressed_pages[pg_index] = alloc_page(GFP_NOFS | |
619 | __GFP_HIGHMEM); | 619 | __GFP_HIGHMEM); |
620 | if (!cb->compressed_pages[page_index]) | 620 | if (!cb->compressed_pages[pg_index]) |
621 | goto fail2; | 621 | goto fail2; |
622 | } | 622 | } |
623 | cb->nr_pages = nr_pages; | 623 | cb->nr_pages = nr_pages; |
@@ -635,8 +635,8 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, | |||
635 | comp_bio->bi_end_io = end_compressed_bio_read; | 635 | comp_bio->bi_end_io = end_compressed_bio_read; |
636 | atomic_inc(&cb->pending_bios); | 636 | atomic_inc(&cb->pending_bios); |
637 | 637 | ||
638 | for (page_index = 0; page_index < nr_pages; page_index++) { | 638 | for (pg_index = 0; pg_index < nr_pages; pg_index++) { |
639 | page = cb->compressed_pages[page_index]; | 639 | page = cb->compressed_pages[pg_index]; |
640 | page->mapping = inode->i_mapping; | 640 | page->mapping = inode->i_mapping; |
641 | page->index = em_start >> PAGE_CACHE_SHIFT; | 641 | page->index = em_start >> PAGE_CACHE_SHIFT; |
642 | 642 | ||
@@ -703,8 +703,8 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, | |||
703 | return 0; | 703 | return 0; |
704 | 704 | ||
705 | fail2: | 705 | fail2: |
706 | for (page_index = 0; page_index < nr_pages; page_index++) | 706 | for (pg_index = 0; pg_index < nr_pages; pg_index++) |
707 | free_page((unsigned long)cb->compressed_pages[page_index]); | 707 | free_page((unsigned long)cb->compressed_pages[pg_index]); |
708 | 708 | ||
709 | kfree(cb->compressed_pages); | 709 | kfree(cb->compressed_pages); |
710 | fail1: | 710 | fail1: |
@@ -946,7 +946,7 @@ void btrfs_exit_compress(void) | |||
946 | int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, | 946 | int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, |
947 | unsigned long total_out, u64 disk_start, | 947 | unsigned long total_out, u64 disk_start, |
948 | struct bio_vec *bvec, int vcnt, | 948 | struct bio_vec *bvec, int vcnt, |
949 | unsigned long *page_index, | 949 | unsigned long *pg_index, |
950 | unsigned long *pg_offset) | 950 | unsigned long *pg_offset) |
951 | { | 951 | { |
952 | unsigned long buf_offset; | 952 | unsigned long buf_offset; |
@@ -955,7 +955,7 @@ int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, | |||
955 | unsigned long working_bytes = total_out - buf_start; | 955 | unsigned long working_bytes = total_out - buf_start; |
956 | unsigned long bytes; | 956 | unsigned long bytes; |
957 | char *kaddr; | 957 | char *kaddr; |
958 | struct page *page_out = bvec[*page_index].bv_page; | 958 | struct page *page_out = bvec[*pg_index].bv_page; |
959 | 959 | ||
960 | /* | 960 | /* |
961 | * start byte is the first byte of the page we're currently | 961 | * start byte is the first byte of the page we're currently |
@@ -996,11 +996,11 @@ int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, | |||
996 | 996 | ||
997 | /* check if we need to pick another page */ | 997 | /* check if we need to pick another page */ |
998 | if (*pg_offset == PAGE_CACHE_SIZE) { | 998 | if (*pg_offset == PAGE_CACHE_SIZE) { |
999 | (*page_index)++; | 999 | (*pg_index)++; |
1000 | if (*page_index >= vcnt) | 1000 | if (*pg_index >= vcnt) |
1001 | return 0; | 1001 | return 0; |
1002 | 1002 | ||
1003 | page_out = bvec[*page_index].bv_page; | 1003 | page_out = bvec[*pg_index].bv_page; |
1004 | *pg_offset = 0; | 1004 | *pg_offset = 0; |
1005 | start_byte = page_offset(page_out) - disk_start; | 1005 | start_byte = page_offset(page_out) - disk_start; |
1006 | 1006 | ||
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 51000174b9d7..a12059f4f0fd 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h | |||
@@ -37,7 +37,7 @@ int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page, | |||
37 | int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, | 37 | int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, |
38 | unsigned long total_out, u64 disk_start, | 38 | unsigned long total_out, u64 disk_start, |
39 | struct bio_vec *bvec, int vcnt, | 39 | struct bio_vec *bvec, int vcnt, |
40 | unsigned long *page_index, | 40 | unsigned long *pg_index, |
41 | unsigned long *pg_offset); | 41 | unsigned long *pg_offset); |
42 | 42 | ||
43 | int btrfs_submit_compressed_write(struct inode *inode, u64 start, | 43 | int btrfs_submit_compressed_write(struct inode *inode, u64 start, |
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 2736b6b2ff5f..b6cbeed226b1 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -102,7 +102,7 @@ void btrfs_free_path(struct btrfs_path *p) | |||
102 | { | 102 | { |
103 | if (!p) | 103 | if (!p) |
104 | return; | 104 | return; |
105 | btrfs_release_path(NULL, p); | 105 | btrfs_release_path(p); |
106 | kmem_cache_free(btrfs_path_cachep, p); | 106 | kmem_cache_free(btrfs_path_cachep, p); |
107 | } | 107 | } |
108 | 108 | ||
@@ -112,7 +112,7 @@ void btrfs_free_path(struct btrfs_path *p) | |||
112 | * | 112 | * |
113 | * It is safe to call this on paths that no locks or extent buffers held. | 113 | * It is safe to call this on paths that no locks or extent buffers held. |
114 | */ | 114 | */ |
115 | noinline void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p) | 115 | noinline void btrfs_release_path(struct btrfs_path *p) |
116 | { | 116 | { |
117 | int i; | 117 | int i; |
118 | 118 | ||
@@ -1323,7 +1323,7 @@ static noinline int reada_for_balance(struct btrfs_root *root, | |||
1323 | ret = -EAGAIN; | 1323 | ret = -EAGAIN; |
1324 | 1324 | ||
1325 | /* release the whole path */ | 1325 | /* release the whole path */ |
1326 | btrfs_release_path(root, path); | 1326 | btrfs_release_path(path); |
1327 | 1327 | ||
1328 | /* read the blocks */ | 1328 | /* read the blocks */ |
1329 | if (block1) | 1329 | if (block1) |
@@ -1470,7 +1470,7 @@ read_block_for_search(struct btrfs_trans_handle *trans, | |||
1470 | return 0; | 1470 | return 0; |
1471 | } | 1471 | } |
1472 | free_extent_buffer(tmp); | 1472 | free_extent_buffer(tmp); |
1473 | btrfs_release_path(NULL, p); | 1473 | btrfs_release_path(p); |
1474 | return -EIO; | 1474 | return -EIO; |
1475 | } | 1475 | } |
1476 | } | 1476 | } |
@@ -1489,7 +1489,7 @@ read_block_for_search(struct btrfs_trans_handle *trans, | |||
1489 | if (p->reada) | 1489 | if (p->reada) |
1490 | reada_for_search(root, p, level, slot, key->objectid); | 1490 | reada_for_search(root, p, level, slot, key->objectid); |
1491 | 1491 | ||
1492 | btrfs_release_path(NULL, p); | 1492 | btrfs_release_path(p); |
1493 | 1493 | ||
1494 | ret = -EAGAIN; | 1494 | ret = -EAGAIN; |
1495 | tmp = read_tree_block(root, blocknr, blocksize, 0); | 1495 | tmp = read_tree_block(root, blocknr, blocksize, 0); |
@@ -1558,7 +1558,7 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans, | |||
1558 | } | 1558 | } |
1559 | b = p->nodes[level]; | 1559 | b = p->nodes[level]; |
1560 | if (!b) { | 1560 | if (!b) { |
1561 | btrfs_release_path(NULL, p); | 1561 | btrfs_release_path(p); |
1562 | goto again; | 1562 | goto again; |
1563 | } | 1563 | } |
1564 | BUG_ON(btrfs_header_nritems(b) == 1); | 1564 | BUG_ON(btrfs_header_nritems(b) == 1); |
@@ -1748,7 +1748,7 @@ done: | |||
1748 | if (!p->leave_spinning) | 1748 | if (!p->leave_spinning) |
1749 | btrfs_set_path_blocking(p); | 1749 | btrfs_set_path_blocking(p); |
1750 | if (ret < 0) | 1750 | if (ret < 0) |
1751 | btrfs_release_path(root, p); | 1751 | btrfs_release_path(p); |
1752 | return ret; | 1752 | return ret; |
1753 | } | 1753 | } |
1754 | 1754 | ||
@@ -3021,7 +3021,7 @@ static noinline int setup_leaf_for_split(struct btrfs_trans_handle *trans, | |||
3021 | struct btrfs_file_extent_item); | 3021 | struct btrfs_file_extent_item); |
3022 | extent_len = btrfs_file_extent_num_bytes(leaf, fi); | 3022 | extent_len = btrfs_file_extent_num_bytes(leaf, fi); |
3023 | } | 3023 | } |
3024 | btrfs_release_path(root, path); | 3024 | btrfs_release_path(path); |
3025 | 3025 | ||
3026 | path->keep_locks = 1; | 3026 | path->keep_locks = 1; |
3027 | path->search_for_split = 1; | 3027 | path->search_for_split = 1; |
@@ -3641,7 +3641,6 @@ int setup_items_for_insert(struct btrfs_trans_handle *trans, | |||
3641 | 3641 | ||
3642 | ret = 0; | 3642 | ret = 0; |
3643 | if (slot == 0) { | 3643 | if (slot == 0) { |
3644 | struct btrfs_disk_key disk_key; | ||
3645 | btrfs_cpu_key_to_disk(&disk_key, cpu_key); | 3644 | btrfs_cpu_key_to_disk(&disk_key, cpu_key); |
3646 | ret = fixup_low_keys(trans, root, path, &disk_key, 1); | 3645 | ret = fixup_low_keys(trans, root, path, &disk_key, 1); |
3647 | } | 3646 | } |
@@ -3943,7 +3942,7 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path) | |||
3943 | else | 3942 | else |
3944 | return 1; | 3943 | return 1; |
3945 | 3944 | ||
3946 | btrfs_release_path(root, path); | 3945 | btrfs_release_path(path); |
3947 | ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); | 3946 | ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); |
3948 | if (ret < 0) | 3947 | if (ret < 0) |
3949 | return ret; | 3948 | return ret; |
@@ -4067,7 +4066,7 @@ find_next_key: | |||
4067 | sret = btrfs_find_next_key(root, path, min_key, level, | 4066 | sret = btrfs_find_next_key(root, path, min_key, level, |
4068 | cache_only, min_trans); | 4067 | cache_only, min_trans); |
4069 | if (sret == 0) { | 4068 | if (sret == 0) { |
4070 | btrfs_release_path(root, path); | 4069 | btrfs_release_path(path); |
4071 | goto again; | 4070 | goto again; |
4072 | } else { | 4071 | } else { |
4073 | goto out; | 4072 | goto out; |
@@ -4146,7 +4145,7 @@ next: | |||
4146 | btrfs_node_key_to_cpu(c, &cur_key, slot); | 4145 | btrfs_node_key_to_cpu(c, &cur_key, slot); |
4147 | 4146 | ||
4148 | orig_lowest = path->lowest_level; | 4147 | orig_lowest = path->lowest_level; |
4149 | btrfs_release_path(root, path); | 4148 | btrfs_release_path(path); |
4150 | path->lowest_level = level; | 4149 | path->lowest_level = level; |
4151 | ret = btrfs_search_slot(NULL, root, &cur_key, path, | 4150 | ret = btrfs_search_slot(NULL, root, &cur_key, path, |
4152 | 0, 0); | 4151 | 0, 0); |
@@ -4223,7 +4222,7 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path) | |||
4223 | again: | 4222 | again: |
4224 | level = 1; | 4223 | level = 1; |
4225 | next = NULL; | 4224 | next = NULL; |
4226 | btrfs_release_path(root, path); | 4225 | btrfs_release_path(path); |
4227 | 4226 | ||
4228 | path->keep_locks = 1; | 4227 | path->keep_locks = 1; |
4229 | 4228 | ||
@@ -4279,7 +4278,7 @@ again: | |||
4279 | goto again; | 4278 | goto again; |
4280 | 4279 | ||
4281 | if (ret < 0) { | 4280 | if (ret < 0) { |
4282 | btrfs_release_path(root, path); | 4281 | btrfs_release_path(path); |
4283 | goto done; | 4282 | goto done; |
4284 | } | 4283 | } |
4285 | 4284 | ||
@@ -4318,7 +4317,7 @@ again: | |||
4318 | goto again; | 4317 | goto again; |
4319 | 4318 | ||
4320 | if (ret < 0) { | 4319 | if (ret < 0) { |
4321 | btrfs_release_path(root, path); | 4320 | btrfs_release_path(path); |
4322 | goto done; | 4321 | goto done; |
4323 | } | 4322 | } |
4324 | 4323 | ||
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 529c157000b1..e7d40791ec9f 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -746,12 +746,12 @@ struct btrfs_space_info { | |||
746 | */ | 746 | */ |
747 | unsigned long reservation_progress; | 747 | unsigned long reservation_progress; |
748 | 748 | ||
749 | int full:1; /* indicates that we cannot allocate any more | 749 | unsigned int full:1; /* indicates that we cannot allocate any more |
750 | chunks for this space */ | 750 | chunks for this space */ |
751 | int chunk_alloc:1; /* set if we are allocating a chunk */ | 751 | unsigned int chunk_alloc:1; /* set if we are allocating a chunk */ |
752 | 752 | ||
753 | int force_alloc; /* set if we need to force a chunk alloc for | 753 | unsigned int force_alloc; /* set if we need to force a chunk |
754 | this space */ | 754 | alloc for this space */ |
755 | 755 | ||
756 | struct list_head list; | 756 | struct list_head list; |
757 | 757 | ||
@@ -1463,26 +1463,12 @@ static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb, | |||
1463 | return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr)); | 1463 | return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr)); |
1464 | } | 1464 | } |
1465 | 1465 | ||
1466 | static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb, | ||
1467 | struct btrfs_chunk *c, int nr, | ||
1468 | u64 val) | ||
1469 | { | ||
1470 | btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val); | ||
1471 | } | ||
1472 | |||
1473 | static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb, | 1466 | static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb, |
1474 | struct btrfs_chunk *c, int nr) | 1467 | struct btrfs_chunk *c, int nr) |
1475 | { | 1468 | { |
1476 | return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr)); | 1469 | return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr)); |
1477 | } | 1470 | } |
1478 | 1471 | ||
1479 | static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb, | ||
1480 | struct btrfs_chunk *c, int nr, | ||
1481 | u64 val) | ||
1482 | { | ||
1483 | btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val); | ||
1484 | } | ||
1485 | |||
1486 | /* struct btrfs_block_group_item */ | 1472 | /* struct btrfs_block_group_item */ |
1487 | BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item, | 1473 | BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item, |
1488 | used, 64); | 1474 | used, 64); |
@@ -1540,14 +1526,6 @@ btrfs_inode_ctime(struct btrfs_inode_item *inode_item) | |||
1540 | return (struct btrfs_timespec *)ptr; | 1526 | return (struct btrfs_timespec *)ptr; |
1541 | } | 1527 | } |
1542 | 1528 | ||
1543 | static inline struct btrfs_timespec * | ||
1544 | btrfs_inode_otime(struct btrfs_inode_item *inode_item) | ||
1545 | { | ||
1546 | unsigned long ptr = (unsigned long)inode_item; | ||
1547 | ptr += offsetof(struct btrfs_inode_item, otime); | ||
1548 | return (struct btrfs_timespec *)ptr; | ||
1549 | } | ||
1550 | |||
1551 | BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64); | 1529 | BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64); |
1552 | BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32); | 1530 | BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32); |
1553 | 1531 | ||
@@ -1898,33 +1876,6 @@ static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb) | |||
1898 | return (u8 *)ptr; | 1876 | return (u8 *)ptr; |
1899 | } | 1877 | } |
1900 | 1878 | ||
1901 | static inline u8 *btrfs_super_fsid(struct extent_buffer *eb) | ||
1902 | { | ||
1903 | unsigned long ptr = offsetof(struct btrfs_super_block, fsid); | ||
1904 | return (u8 *)ptr; | ||
1905 | } | ||
1906 | |||
1907 | static inline u8 *btrfs_header_csum(struct extent_buffer *eb) | ||
1908 | { | ||
1909 | unsigned long ptr = offsetof(struct btrfs_header, csum); | ||
1910 | return (u8 *)ptr; | ||
1911 | } | ||
1912 | |||
1913 | static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb) | ||
1914 | { | ||
1915 | return NULL; | ||
1916 | } | ||
1917 | |||
1918 | static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb) | ||
1919 | { | ||
1920 | return NULL; | ||
1921 | } | ||
1922 | |||
1923 | static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb) | ||
1924 | { | ||
1925 | return NULL; | ||
1926 | } | ||
1927 | |||
1928 | static inline int btrfs_is_leaf(struct extent_buffer *eb) | 1879 | static inline int btrfs_is_leaf(struct extent_buffer *eb) |
1929 | { | 1880 | { |
1930 | return btrfs_header_level(eb) == 0; | 1881 | return btrfs_header_level(eb) == 0; |
@@ -2078,22 +2029,6 @@ static inline struct btrfs_root *btrfs_sb(struct super_block *sb) | |||
2078 | return sb->s_fs_info; | 2029 | return sb->s_fs_info; |
2079 | } | 2030 | } |
2080 | 2031 | ||
2081 | static inline int btrfs_set_root_name(struct btrfs_root *root, | ||
2082 | const char *name, int len) | ||
2083 | { | ||
2084 | /* if we already have a name just free it */ | ||
2085 | kfree(root->name); | ||
2086 | |||
2087 | root->name = kmalloc(len+1, GFP_KERNEL); | ||
2088 | if (!root->name) | ||
2089 | return -ENOMEM; | ||
2090 | |||
2091 | memcpy(root->name, name, len); | ||
2092 | root->name[len] = '\0'; | ||
2093 | |||
2094 | return 0; | ||
2095 | } | ||
2096 | |||
2097 | static inline u32 btrfs_level_size(struct btrfs_root *root, int level) | 2032 | static inline u32 btrfs_level_size(struct btrfs_root *root, int level) |
2098 | { | 2033 | { |
2099 | if (level == 0) | 2034 | if (level == 0) |
@@ -2138,12 +2073,9 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, | |||
2138 | u64 num_bytes, u64 *refs, u64 *flags); | 2073 | u64 num_bytes, u64 *refs, u64 *flags); |
2139 | int btrfs_pin_extent(struct btrfs_root *root, | 2074 | int btrfs_pin_extent(struct btrfs_root *root, |
2140 | u64 bytenr, u64 num, int reserved); | 2075 | u64 bytenr, u64 num, int reserved); |
2141 | int btrfs_drop_leaf_ref(struct btrfs_trans_handle *trans, | ||
2142 | struct btrfs_root *root, struct extent_buffer *leaf); | ||
2143 | int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans, | 2076 | int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans, |
2144 | struct btrfs_root *root, | 2077 | struct btrfs_root *root, |
2145 | u64 objectid, u64 offset, u64 bytenr); | 2078 | u64 objectid, u64 offset, u64 bytenr); |
2146 | int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy); | ||
2147 | struct btrfs_block_group_cache *btrfs_lookup_block_group( | 2079 | struct btrfs_block_group_cache *btrfs_lookup_block_group( |
2148 | struct btrfs_fs_info *info, | 2080 | struct btrfs_fs_info *info, |
2149 | u64 bytenr); | 2081 | u64 bytenr); |
@@ -2320,7 +2252,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, | |||
2320 | struct btrfs_root *root, struct extent_buffer *parent, | 2252 | struct btrfs_root *root, struct extent_buffer *parent, |
2321 | int start_slot, int cache_only, u64 *last_ret, | 2253 | int start_slot, int cache_only, u64 *last_ret, |
2322 | struct btrfs_key *progress); | 2254 | struct btrfs_key *progress); |
2323 | void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); | 2255 | void btrfs_release_path(struct btrfs_path *p); |
2324 | struct btrfs_path *btrfs_alloc_path(void); | 2256 | struct btrfs_path *btrfs_alloc_path(void); |
2325 | void btrfs_free_path(struct btrfs_path *p); | 2257 | void btrfs_free_path(struct btrfs_path *p); |
2326 | void btrfs_set_path_blocking(struct btrfs_path *p); | 2258 | void btrfs_set_path_blocking(struct btrfs_path *p); |
@@ -2343,11 +2275,6 @@ int setup_items_for_insert(struct btrfs_trans_handle *trans, | |||
2343 | u32 total_data, u32 total_size, int nr); | 2275 | u32 total_data, u32 total_size, int nr); |
2344 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root | 2276 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root |
2345 | *root, struct btrfs_key *key, void *data, u32 data_size); | 2277 | *root, struct btrfs_key *key, void *data, u32 data_size); |
2346 | int btrfs_insert_some_items(struct btrfs_trans_handle *trans, | ||
2347 | struct btrfs_root *root, | ||
2348 | struct btrfs_path *path, | ||
2349 | struct btrfs_key *cpu_key, u32 *data_size, | ||
2350 | int nr); | ||
2351 | int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, | 2278 | int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, |
2352 | struct btrfs_root *root, | 2279 | struct btrfs_root *root, |
2353 | struct btrfs_path *path, | 2280 | struct btrfs_path *path, |
@@ -2393,8 +2320,6 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root | |||
2393 | *item); | 2320 | *item); |
2394 | int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct | 2321 | int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct |
2395 | btrfs_root_item *item, struct btrfs_key *key); | 2322 | btrfs_root_item *item, struct btrfs_key *key); |
2396 | int btrfs_search_root(struct btrfs_root *root, u64 search_start, | ||
2397 | u64 *found_objectid); | ||
2398 | int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid); | 2323 | int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid); |
2399 | int btrfs_find_orphan_roots(struct btrfs_root *tree_root); | 2324 | int btrfs_find_orphan_roots(struct btrfs_root *tree_root); |
2400 | int btrfs_set_root_node(struct btrfs_root_item *item, | 2325 | int btrfs_set_root_node(struct btrfs_root_item *item, |
@@ -2493,15 +2418,10 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, | |||
2493 | struct btrfs_ordered_sum *sums); | 2418 | struct btrfs_ordered_sum *sums); |
2494 | int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, | 2419 | int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, |
2495 | struct bio *bio, u64 file_start, int contig); | 2420 | struct bio *bio, u64 file_start, int contig); |
2496 | int btrfs_csum_file_bytes(struct btrfs_root *root, struct inode *inode, | ||
2497 | u64 start, unsigned long len); | ||
2498 | struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, | 2421 | struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, |
2499 | struct btrfs_root *root, | 2422 | struct btrfs_root *root, |
2500 | struct btrfs_path *path, | 2423 | struct btrfs_path *path, |
2501 | u64 bytenr, int cow); | 2424 | u64 bytenr, int cow); |
2502 | int btrfs_csum_truncate(struct btrfs_trans_handle *trans, | ||
2503 | struct btrfs_root *root, struct btrfs_path *path, | ||
2504 | u64 isize); | ||
2505 | int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, | 2425 | int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, |
2506 | u64 end, struct list_head *list); | 2426 | u64 end, struct list_head *list); |
2507 | /* inode.c */ | 2427 | /* inode.c */ |
@@ -2532,8 +2452,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, | |||
2532 | u32 min_type); | 2452 | u32 min_type); |
2533 | 2453 | ||
2534 | int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput); | 2454 | int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput); |
2535 | int btrfs_start_one_delalloc_inode(struct btrfs_root *root, int delay_iput, | ||
2536 | int sync); | ||
2537 | int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, | 2455 | int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, |
2538 | struct extent_state **cached_state); | 2456 | struct extent_state **cached_state); |
2539 | int btrfs_writepages(struct address_space *mapping, | 2457 | int btrfs_writepages(struct address_space *mapping, |
@@ -2550,7 +2468,6 @@ unsigned long btrfs_force_ra(struct address_space *mapping, | |||
2550 | int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf); | 2468 | int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf); |
2551 | int btrfs_readpage(struct file *file, struct page *page); | 2469 | int btrfs_readpage(struct file *file, struct page *page); |
2552 | void btrfs_evict_inode(struct inode *inode); | 2470 | void btrfs_evict_inode(struct inode *inode); |
2553 | void btrfs_put_inode(struct inode *inode); | ||
2554 | int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc); | 2471 | int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc); |
2555 | void btrfs_dirty_inode(struct inode *inode); | 2472 | void btrfs_dirty_inode(struct inode *inode); |
2556 | struct inode *btrfs_alloc_inode(struct super_block *sb); | 2473 | struct inode *btrfs_alloc_inode(struct super_block *sb); |
@@ -2561,10 +2478,8 @@ void btrfs_destroy_cachep(void); | |||
2561 | long btrfs_ioctl_trans_end(struct file *file); | 2478 | long btrfs_ioctl_trans_end(struct file *file); |
2562 | struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, | 2479 | struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, |
2563 | struct btrfs_root *root, int *was_new); | 2480 | struct btrfs_root *root, int *was_new); |
2564 | int btrfs_commit_write(struct file *file, struct page *page, | ||
2565 | unsigned from, unsigned to); | ||
2566 | struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, | 2481 | struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, |
2567 | size_t page_offset, u64 start, u64 end, | 2482 | size_t pg_offset, u64 start, u64 end, |
2568 | int create); | 2483 | int create); |
2569 | int btrfs_update_inode(struct btrfs_trans_handle *trans, | 2484 | int btrfs_update_inode(struct btrfs_trans_handle *trans, |
2570 | struct btrfs_root *root, | 2485 | struct btrfs_root *root, |
@@ -2601,7 +2516,6 @@ void btrfs_inherit_iflags(struct inode *inode, struct inode *dir); | |||
2601 | int btrfs_sync_file(struct file *file, int datasync); | 2516 | int btrfs_sync_file(struct file *file, int datasync); |
2602 | int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, | 2517 | int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, |
2603 | int skip_pinned); | 2518 | int skip_pinned); |
2604 | int btrfs_check_file(struct btrfs_root *root, struct inode *inode); | ||
2605 | extern const struct file_operations btrfs_file_operations; | 2519 | extern const struct file_operations btrfs_file_operations; |
2606 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, | 2520 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, |
2607 | u64 start, u64 end, u64 *hint_byte, int drop_cache); | 2521 | u64 start, u64 end, u64 *hint_byte, int drop_cache); |
@@ -2621,10 +2535,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, | |||
2621 | /* sysfs.c */ | 2535 | /* sysfs.c */ |
2622 | int btrfs_init_sysfs(void); | 2536 | int btrfs_init_sysfs(void); |
2623 | void btrfs_exit_sysfs(void); | 2537 | void btrfs_exit_sysfs(void); |
2624 | int btrfs_sysfs_add_super(struct btrfs_fs_info *fs); | ||
2625 | int btrfs_sysfs_add_root(struct btrfs_root *root); | ||
2626 | void btrfs_sysfs_del_root(struct btrfs_root *root); | ||
2627 | void btrfs_sysfs_del_super(struct btrfs_fs_info *root); | ||
2628 | 2538 | ||
2629 | /* xattr.c */ | 2539 | /* xattr.c */ |
2630 | ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size); | 2540 | ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size); |
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index c25405f69360..01e29503a54b 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c | |||
@@ -813,7 +813,7 @@ do_again: | |||
813 | 813 | ||
814 | ret = btrfs_insert_delayed_item(trans, root, path, curr); | 814 | ret = btrfs_insert_delayed_item(trans, root, path, curr); |
815 | if (ret < 0) { | 815 | if (ret < 0) { |
816 | btrfs_release_path(root, path); | 816 | btrfs_release_path(path); |
817 | goto insert_end; | 817 | goto insert_end; |
818 | } | 818 | } |
819 | 819 | ||
@@ -827,7 +827,7 @@ do_again: | |||
827 | btrfs_release_delayed_item(prev); | 827 | btrfs_release_delayed_item(prev); |
828 | btrfs_mark_buffer_dirty(path->nodes[0]); | 828 | btrfs_mark_buffer_dirty(path->nodes[0]); |
829 | 829 | ||
830 | btrfs_release_path(root, path); | 830 | btrfs_release_path(path); |
831 | mutex_unlock(&node->mutex); | 831 | mutex_unlock(&node->mutex); |
832 | goto do_again; | 832 | goto do_again; |
833 | 833 | ||
@@ -925,7 +925,7 @@ do_again: | |||
925 | curr = __btrfs_next_delayed_item(prev); | 925 | curr = __btrfs_next_delayed_item(prev); |
926 | btrfs_release_delayed_item(prev); | 926 | btrfs_release_delayed_item(prev); |
927 | ret = 0; | 927 | ret = 0; |
928 | btrfs_release_path(root, path); | 928 | btrfs_release_path(path); |
929 | if (curr) | 929 | if (curr) |
930 | goto do_again; | 930 | goto do_again; |
931 | else | 931 | else |
@@ -933,12 +933,12 @@ do_again: | |||
933 | } | 933 | } |
934 | 934 | ||
935 | btrfs_batch_delete_items(trans, root, path, curr); | 935 | btrfs_batch_delete_items(trans, root, path, curr); |
936 | btrfs_release_path(root, path); | 936 | btrfs_release_path(path); |
937 | mutex_unlock(&node->mutex); | 937 | mutex_unlock(&node->mutex); |
938 | goto do_again; | 938 | goto do_again; |
939 | 939 | ||
940 | delete_fail: | 940 | delete_fail: |
941 | btrfs_release_path(root, path); | 941 | btrfs_release_path(path); |
942 | mutex_unlock(&node->mutex); | 942 | mutex_unlock(&node->mutex); |
943 | return ret; | 943 | return ret; |
944 | } | 944 | } |
@@ -982,7 +982,7 @@ static int btrfs_update_delayed_inode(struct btrfs_trans_handle *trans, | |||
982 | key.offset = 0; | 982 | key.offset = 0; |
983 | ret = btrfs_lookup_inode(trans, root, path, &key, 1); | 983 | ret = btrfs_lookup_inode(trans, root, path, &key, 1); |
984 | if (ret > 0) { | 984 | if (ret > 0) { |
985 | btrfs_release_path(root, path); | 985 | btrfs_release_path(path); |
986 | mutex_unlock(&node->mutex); | 986 | mutex_unlock(&node->mutex); |
987 | return -ENOENT; | 987 | return -ENOENT; |
988 | } else if (ret < 0) { | 988 | } else if (ret < 0) { |
@@ -997,7 +997,7 @@ static int btrfs_update_delayed_inode(struct btrfs_trans_handle *trans, | |||
997 | write_extent_buffer(leaf, &node->inode_item, (unsigned long)inode_item, | 997 | write_extent_buffer(leaf, &node->inode_item, (unsigned long)inode_item, |
998 | sizeof(struct btrfs_inode_item)); | 998 | sizeof(struct btrfs_inode_item)); |
999 | btrfs_mark_buffer_dirty(leaf); | 999 | btrfs_mark_buffer_dirty(leaf); |
1000 | btrfs_release_path(root, path); | 1000 | btrfs_release_path(path); |
1001 | 1001 | ||
1002 | btrfs_delayed_inode_release_metadata(root, node); | 1002 | btrfs_delayed_inode_release_metadata(root, node); |
1003 | btrfs_release_delayed_inode(node); | 1003 | btrfs_release_delayed_inode(node); |
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index bce28f653899..125cf76fcd08 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c | |||
@@ -281,44 +281,6 @@ again: | |||
281 | } | 281 | } |
282 | 282 | ||
283 | /* | 283 | /* |
284 | * This checks to see if there are any delayed refs in the | ||
285 | * btree for a given bytenr. It returns one if it finds any | ||
286 | * and zero otherwise. | ||
287 | * | ||
288 | * If it only finds a head node, it returns 0. | ||
289 | * | ||
290 | * The idea is to use this when deciding if you can safely delete an | ||
291 | * extent from the extent allocation tree. There may be a pending | ||
292 | * ref in the rbtree that adds or removes references, so as long as this | ||
293 | * returns one you need to leave the BTRFS_EXTENT_ITEM in the extent | ||
294 | * allocation tree. | ||
295 | */ | ||
296 | int btrfs_delayed_ref_pending(struct btrfs_trans_handle *trans, u64 bytenr) | ||
297 | { | ||
298 | struct btrfs_delayed_ref_node *ref; | ||
299 | struct btrfs_delayed_ref_root *delayed_refs; | ||
300 | struct rb_node *prev_node; | ||
301 | int ret = 0; | ||
302 | |||
303 | delayed_refs = &trans->transaction->delayed_refs; | ||
304 | spin_lock(&delayed_refs->lock); | ||
305 | |||
306 | ref = find_ref_head(&delayed_refs->root, bytenr, NULL); | ||
307 | if (ref) { | ||
308 | prev_node = rb_prev(&ref->rb_node); | ||
309 | if (!prev_node) | ||
310 | goto out; | ||
311 | ref = rb_entry(prev_node, struct btrfs_delayed_ref_node, | ||
312 | rb_node); | ||
313 | if (ref->bytenr == bytenr) | ||
314 | ret = 1; | ||
315 | } | ||
316 | out: | ||
317 | spin_unlock(&delayed_refs->lock); | ||
318 | return ret; | ||
319 | } | ||
320 | |||
321 | /* | ||
322 | * helper function to update an extent delayed ref in the | 284 | * helper function to update an extent delayed ref in the |
323 | * rbtree. existing and update must both have the same | 285 | * rbtree. existing and update must both have the same |
324 | * bytenr and parent | 286 | * bytenr and parent |
@@ -747,79 +709,3 @@ btrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr) | |||
747 | return btrfs_delayed_node_to_head(ref); | 709 | return btrfs_delayed_node_to_head(ref); |
748 | return NULL; | 710 | return NULL; |
749 | } | 711 | } |
750 | |||
751 | /* | ||
752 | * add a delayed ref to the tree. This does all of the accounting required | ||
753 | * to make sure the delayed ref is eventually processed before this | ||
754 | * transaction commits. | ||
755 | * | ||
756 | * The main point of this call is to add and remove a backreference in a single | ||
757 | * shot, taking the lock only once, and only searching for the head node once. | ||
758 | * | ||
759 | * It is the same as doing a ref add and delete in two separate calls. | ||
760 | */ | ||
761 | #if 0 | ||
762 | int btrfs_update_delayed_ref(struct btrfs_trans_handle *trans, | ||
763 | u64 bytenr, u64 num_bytes, u64 orig_parent, | ||
764 | u64 parent, u64 orig_ref_root, u64 ref_root, | ||
765 | u64 orig_ref_generation, u64 ref_generation, | ||
766 | u64 owner_objectid, int pin) | ||
767 | { | ||
768 | struct btrfs_delayed_ref *ref; | ||
769 | struct btrfs_delayed_ref *old_ref; | ||
770 | struct btrfs_delayed_ref_head *head_ref; | ||
771 | struct btrfs_delayed_ref_root *delayed_refs; | ||
772 | int ret; | ||
773 | |||
774 | ref = kmalloc(sizeof(*ref), GFP_NOFS); | ||
775 | if (!ref) | ||
776 | return -ENOMEM; | ||
777 | |||
778 | old_ref = kmalloc(sizeof(*old_ref), GFP_NOFS); | ||
779 | if (!old_ref) { | ||
780 | kfree(ref); | ||
781 | return -ENOMEM; | ||
782 | } | ||
783 | |||
784 | /* | ||
785 | * the parent = 0 case comes from cases where we don't actually | ||
786 | * know the parent yet. It will get updated later via a add/drop | ||
787 | * pair. | ||
788 | */ | ||
789 | if (parent == 0) | ||
790 | parent = bytenr; | ||
791 | if (orig_parent == 0) | ||
792 | orig_parent = bytenr; | ||
793 | |||
794 | head_ref = kmalloc(sizeof(*head_ref), GFP_NOFS); | ||
795 | if (!head_ref) { | ||
796 | kfree(ref); | ||
797 | kfree(old_ref); | ||
798 | return -ENOMEM; | ||
799 | } | ||
800 | delayed_refs = &trans->transaction->delayed_refs; | ||
801 | spin_lock(&delayed_refs->lock); | ||
802 | |||
803 | /* | ||
804 | * insert both the head node and the new ref without dropping | ||
805 | * the spin lock | ||
806 | */ | ||
807 | ret = __btrfs_add_delayed_ref(trans, &head_ref->node, bytenr, num_bytes, | ||
808 | (u64)-1, 0, 0, 0, | ||
809 | BTRFS_UPDATE_DELAYED_HEAD, 0); | ||
810 | BUG_ON(ret); | ||
811 | |||
812 | ret = __btrfs_add_delayed_ref(trans, &ref->node, bytenr, num_bytes, | ||
813 | parent, ref_root, ref_generation, | ||
814 | owner_objectid, BTRFS_ADD_DELAYED_REF, 0); | ||
815 | BUG_ON(ret); | ||
816 | |||
817 | ret = __btrfs_add_delayed_ref(trans, &old_ref->node, bytenr, num_bytes, | ||
818 | orig_parent, orig_ref_root, | ||
819 | orig_ref_generation, owner_objectid, | ||
820 | BTRFS_DROP_DELAYED_REF, pin); | ||
821 | BUG_ON(ret); | ||
822 | spin_unlock(&delayed_refs->lock); | ||
823 | return 0; | ||
824 | } | ||
825 | #endif | ||
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 50e3cf92fbda..e287e3b0eab0 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h | |||
@@ -166,12 +166,6 @@ int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans, | |||
166 | 166 | ||
167 | struct btrfs_delayed_ref_head * | 167 | struct btrfs_delayed_ref_head * |
168 | btrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr); | 168 | btrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr); |
169 | int btrfs_delayed_ref_pending(struct btrfs_trans_handle *trans, u64 bytenr); | ||
170 | int btrfs_update_delayed_ref(struct btrfs_trans_handle *trans, | ||
171 | u64 bytenr, u64 num_bytes, u64 orig_parent, | ||
172 | u64 parent, u64 orig_ref_root, u64 ref_root, | ||
173 | u64 orig_ref_generation, u64 ref_generation, | ||
174 | u64 owner_objectid, int pin); | ||
175 | int btrfs_delayed_ref_lock(struct btrfs_trans_handle *trans, | 169 | int btrfs_delayed_ref_lock(struct btrfs_trans_handle *trans, |
176 | struct btrfs_delayed_ref_head *head); | 170 | struct btrfs_delayed_ref_head *head); |
177 | int btrfs_find_ref_cluster(struct btrfs_trans_handle *trans, | 171 | int btrfs_find_ref_cluster(struct btrfs_trans_handle *trans, |
diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index e757202a014e..1ddfca78e910 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c | |||
@@ -176,7 +176,7 @@ second_insert: | |||
176 | ret = 0; | 176 | ret = 0; |
177 | goto out_free; | 177 | goto out_free; |
178 | } | 178 | } |
179 | btrfs_release_path(root, path); | 179 | btrfs_release_path(path); |
180 | 180 | ||
181 | ret2 = btrfs_insert_delayed_dir_index(trans, root, name, name_len, dir, | 181 | ret2 = btrfs_insert_delayed_dir_index(trans, root, name, name_len, dir, |
182 | &disk_key, type, index); | 182 | &disk_key, type, index); |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 087eed85c250..a2eb3a3755db 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/crc32c.h> | 29 | #include <linux/crc32c.h> |
30 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
31 | #include <linux/migrate.h> | 31 | #include <linux/migrate.h> |
32 | #include <linux/ratelimit.h> | ||
32 | #include <asm/unaligned.h> | 33 | #include <asm/unaligned.h> |
33 | #include "compat.h" | 34 | #include "compat.h" |
34 | #include "ctree.h" | 35 | #include "ctree.h" |
@@ -138,7 +139,7 @@ static const char *btrfs_eb_name[BTRFS_MAX_LEVEL + 1] = { | |||
138 | * that covers the entire device | 139 | * that covers the entire device |
139 | */ | 140 | */ |
140 | static struct extent_map *btree_get_extent(struct inode *inode, | 141 | static struct extent_map *btree_get_extent(struct inode *inode, |
141 | struct page *page, size_t page_offset, u64 start, u64 len, | 142 | struct page *page, size_t pg_offset, u64 start, u64 len, |
142 | int create) | 143 | int create) |
143 | { | 144 | { |
144 | struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; | 145 | struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; |
@@ -155,7 +156,7 @@ static struct extent_map *btree_get_extent(struct inode *inode, | |||
155 | } | 156 | } |
156 | read_unlock(&em_tree->lock); | 157 | read_unlock(&em_tree->lock); |
157 | 158 | ||
158 | em = alloc_extent_map(GFP_NOFS); | 159 | em = alloc_extent_map(); |
159 | if (!em) { | 160 | if (!em) { |
160 | em = ERR_PTR(-ENOMEM); | 161 | em = ERR_PTR(-ENOMEM); |
161 | goto out; | 162 | goto out; |
@@ -255,14 +256,12 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, | |||
255 | memcpy(&found, result, csum_size); | 256 | memcpy(&found, result, csum_size); |
256 | 257 | ||
257 | read_extent_buffer(buf, &val, 0, csum_size); | 258 | read_extent_buffer(buf, &val, 0, csum_size); |
258 | if (printk_ratelimit()) { | 259 | printk_ratelimited(KERN_INFO "btrfs: %s checksum verify " |
259 | printk(KERN_INFO "btrfs: %s checksum verify " | ||
260 | "failed on %llu wanted %X found %X " | 260 | "failed on %llu wanted %X found %X " |
261 | "level %d\n", | 261 | "level %d\n", |
262 | root->fs_info->sb->s_id, | 262 | root->fs_info->sb->s_id, |
263 | (unsigned long long)buf->start, val, found, | 263 | (unsigned long long)buf->start, val, found, |
264 | btrfs_header_level(buf)); | 264 | btrfs_header_level(buf)); |
265 | } | ||
266 | if (result != (char *)&inline_result) | 265 | if (result != (char *)&inline_result) |
267 | kfree(result); | 266 | kfree(result); |
268 | return 1; | 267 | return 1; |
@@ -297,13 +296,11 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, | |||
297 | ret = 0; | 296 | ret = 0; |
298 | goto out; | 297 | goto out; |
299 | } | 298 | } |
300 | if (printk_ratelimit()) { | 299 | printk_ratelimited("parent transid verify failed on %llu wanted %llu " |
301 | printk("parent transid verify failed on %llu wanted %llu " | ||
302 | "found %llu\n", | 300 | "found %llu\n", |
303 | (unsigned long long)eb->start, | 301 | (unsigned long long)eb->start, |
304 | (unsigned long long)parent_transid, | 302 | (unsigned long long)parent_transid, |
305 | (unsigned long long)btrfs_header_generation(eb)); | 303 | (unsigned long long)btrfs_header_generation(eb)); |
306 | } | ||
307 | ret = 1; | 304 | ret = 1; |
308 | clear_extent_buffer_uptodate(io_tree, eb, &cached_state); | 305 | clear_extent_buffer_uptodate(io_tree, eb, &cached_state); |
309 | out: | 306 | out: |
@@ -381,7 +378,7 @@ static int csum_dirty_buffer(struct btrfs_root *root, struct page *page) | |||
381 | len = page->private >> 2; | 378 | len = page->private >> 2; |
382 | WARN_ON(len == 0); | 379 | WARN_ON(len == 0); |
383 | 380 | ||
384 | eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS); | 381 | eb = alloc_extent_buffer(tree, start, len, page); |
385 | if (eb == NULL) { | 382 | if (eb == NULL) { |
386 | WARN_ON(1); | 383 | WARN_ON(1); |
387 | goto out; | 384 | goto out; |
@@ -526,7 +523,7 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, | |||
526 | len = page->private >> 2; | 523 | len = page->private >> 2; |
527 | WARN_ON(len == 0); | 524 | WARN_ON(len == 0); |
528 | 525 | ||
529 | eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS); | 526 | eb = alloc_extent_buffer(tree, start, len, page); |
530 | if (eb == NULL) { | 527 | if (eb == NULL) { |
531 | ret = -EIO; | 528 | ret = -EIO; |
532 | goto out; | 529 | goto out; |
@@ -534,12 +531,10 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, | |||
534 | 531 | ||
535 | found_start = btrfs_header_bytenr(eb); | 532 | found_start = btrfs_header_bytenr(eb); |
536 | if (found_start != start) { | 533 | if (found_start != start) { |
537 | if (printk_ratelimit()) { | 534 | printk_ratelimited(KERN_INFO "btrfs bad tree block start " |
538 | printk(KERN_INFO "btrfs bad tree block start " | ||
539 | "%llu %llu\n", | 535 | "%llu %llu\n", |
540 | (unsigned long long)found_start, | 536 | (unsigned long long)found_start, |
541 | (unsigned long long)eb->start); | 537 | (unsigned long long)eb->start); |
542 | } | ||
543 | ret = -EIO; | 538 | ret = -EIO; |
544 | goto err; | 539 | goto err; |
545 | } | 540 | } |
@@ -551,10 +546,8 @@ static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, | |||
551 | goto err; | 546 | goto err; |
552 | } | 547 | } |
553 | if (check_tree_block_fsid(root, eb)) { | 548 | if (check_tree_block_fsid(root, eb)) { |
554 | if (printk_ratelimit()) { | 549 | printk_ratelimited(KERN_INFO "btrfs bad fsid on block %llu\n", |
555 | printk(KERN_INFO "btrfs bad fsid on block %llu\n", | ||
556 | (unsigned long long)eb->start); | 550 | (unsigned long long)eb->start); |
557 | } | ||
558 | ret = -EIO; | 551 | ret = -EIO; |
559 | goto err; | 552 | goto err; |
560 | } | 553 | } |
@@ -651,12 +644,6 @@ unsigned long btrfs_async_submit_limit(struct btrfs_fs_info *info) | |||
651 | return 256 * limit; | 644 | return 256 * limit; |
652 | } | 645 | } |
653 | 646 | ||
654 | int btrfs_congested_async(struct btrfs_fs_info *info, int iodone) | ||
655 | { | ||
656 | return atomic_read(&info->nr_async_bios) > | ||
657 | btrfs_async_submit_limit(info); | ||
658 | } | ||
659 | |||
660 | static void run_one_async_start(struct btrfs_work *work) | 647 | static void run_one_async_start(struct btrfs_work *work) |
661 | { | 648 | { |
662 | struct async_submit_bio *async; | 649 | struct async_submit_bio *async; |
@@ -964,7 +951,7 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, | |||
964 | struct inode *btree_inode = root->fs_info->btree_inode; | 951 | struct inode *btree_inode = root->fs_info->btree_inode; |
965 | struct extent_buffer *eb; | 952 | struct extent_buffer *eb; |
966 | eb = find_extent_buffer(&BTRFS_I(btree_inode)->io_tree, | 953 | eb = find_extent_buffer(&BTRFS_I(btree_inode)->io_tree, |
967 | bytenr, blocksize, GFP_NOFS); | 954 | bytenr, blocksize); |
968 | return eb; | 955 | return eb; |
969 | } | 956 | } |
970 | 957 | ||
@@ -975,7 +962,7 @@ struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, | |||
975 | struct extent_buffer *eb; | 962 | struct extent_buffer *eb; |
976 | 963 | ||
977 | eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree, | 964 | eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree, |
978 | bytenr, blocksize, NULL, GFP_NOFS); | 965 | bytenr, blocksize, NULL); |
979 | return eb; | 966 | return eb; |
980 | } | 967 | } |
981 | 968 | ||
@@ -1082,7 +1069,7 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
1082 | root->log_transid = 0; | 1069 | root->log_transid = 0; |
1083 | root->last_log_commit = 0; | 1070 | root->last_log_commit = 0; |
1084 | extent_io_tree_init(&root->dirty_log_pages, | 1071 | extent_io_tree_init(&root->dirty_log_pages, |
1085 | fs_info->btree_inode->i_mapping, GFP_NOFS); | 1072 | fs_info->btree_inode->i_mapping); |
1086 | 1073 | ||
1087 | memset(&root->root_key, 0, sizeof(root->root_key)); | 1074 | memset(&root->root_key, 0, sizeof(root->root_key)); |
1088 | memset(&root->root_item, 0, sizeof(root->root_item)); | 1075 | memset(&root->root_item, 0, sizeof(root->root_item)); |
@@ -1285,21 +1272,6 @@ out: | |||
1285 | return root; | 1272 | return root; |
1286 | } | 1273 | } |
1287 | 1274 | ||
1288 | struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info, | ||
1289 | u64 root_objectid) | ||
1290 | { | ||
1291 | struct btrfs_root *root; | ||
1292 | |||
1293 | if (root_objectid == BTRFS_ROOT_TREE_OBJECTID) | ||
1294 | return fs_info->tree_root; | ||
1295 | if (root_objectid == BTRFS_EXTENT_TREE_OBJECTID) | ||
1296 | return fs_info->extent_root; | ||
1297 | |||
1298 | root = radix_tree_lookup(&fs_info->fs_roots_radix, | ||
1299 | (unsigned long)root_objectid); | ||
1300 | return root; | ||
1301 | } | ||
1302 | |||
1303 | struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info, | 1275 | struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info, |
1304 | struct btrfs_key *location) | 1276 | struct btrfs_key *location) |
1305 | { | 1277 | { |
@@ -1384,41 +1356,6 @@ fail: | |||
1384 | return ERR_PTR(ret); | 1356 | return ERR_PTR(ret); |
1385 | } | 1357 | } |
1386 | 1358 | ||
1387 | struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info, | ||
1388 | struct btrfs_key *location, | ||
1389 | const char *name, int namelen) | ||
1390 | { | ||
1391 | return btrfs_read_fs_root_no_name(fs_info, location); | ||
1392 | #if 0 | ||
1393 | struct btrfs_root *root; | ||
1394 | int ret; | ||
1395 | |||
1396 | root = btrfs_read_fs_root_no_name(fs_info, location); | ||
1397 | if (!root) | ||
1398 | return NULL; | ||
1399 | |||
1400 | if (root->in_sysfs) | ||
1401 | return root; | ||
1402 | |||
1403 | ret = btrfs_set_root_name(root, name, namelen); | ||
1404 | if (ret) { | ||
1405 | free_extent_buffer(root->node); | ||
1406 | kfree(root); | ||
1407 | return ERR_PTR(ret); | ||
1408 | } | ||
1409 | |||
1410 | ret = btrfs_sysfs_add_root(root); | ||
1411 | if (ret) { | ||
1412 | free_extent_buffer(root->node); | ||
1413 | kfree(root->name); | ||
1414 | kfree(root); | ||
1415 | return ERR_PTR(ret); | ||
1416 | } | ||
1417 | root->in_sysfs = 1; | ||
1418 | return root; | ||
1419 | #endif | ||
1420 | } | ||
1421 | |||
1422 | static int btrfs_congested_fn(void *congested_data, int bdi_bits) | 1359 | static int btrfs_congested_fn(void *congested_data, int bdi_bits) |
1423 | { | 1360 | { |
1424 | struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data; | 1361 | struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data; |
@@ -1626,7 +1563,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1626 | struct btrfs_root *csum_root = kzalloc(sizeof(struct btrfs_root), | 1563 | struct btrfs_root *csum_root = kzalloc(sizeof(struct btrfs_root), |
1627 | GFP_NOFS); | 1564 | GFP_NOFS); |
1628 | struct btrfs_root *tree_root = btrfs_sb(sb); | 1565 | struct btrfs_root *tree_root = btrfs_sb(sb); |
1629 | struct btrfs_fs_info *fs_info = tree_root->fs_info; | 1566 | struct btrfs_fs_info *fs_info = NULL; |
1630 | struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root), | 1567 | struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root), |
1631 | GFP_NOFS); | 1568 | GFP_NOFS); |
1632 | struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root), | 1569 | struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root), |
@@ -1638,11 +1575,12 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1638 | 1575 | ||
1639 | struct btrfs_super_block *disk_super; | 1576 | struct btrfs_super_block *disk_super; |
1640 | 1577 | ||
1641 | if (!extent_root || !tree_root || !fs_info || | 1578 | if (!extent_root || !tree_root || !tree_root->fs_info || |
1642 | !chunk_root || !dev_root || !csum_root) { | 1579 | !chunk_root || !dev_root || !csum_root) { |
1643 | err = -ENOMEM; | 1580 | err = -ENOMEM; |
1644 | goto fail; | 1581 | goto fail; |
1645 | } | 1582 | } |
1583 | fs_info = tree_root->fs_info; | ||
1646 | 1584 | ||
1647 | ret = init_srcu_struct(&fs_info->subvol_srcu); | 1585 | ret = init_srcu_struct(&fs_info->subvol_srcu); |
1648 | if (ret) { | 1586 | if (ret) { |
@@ -1733,10 +1671,8 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1733 | 1671 | ||
1734 | RB_CLEAR_NODE(&BTRFS_I(fs_info->btree_inode)->rb_node); | 1672 | RB_CLEAR_NODE(&BTRFS_I(fs_info->btree_inode)->rb_node); |
1735 | extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree, | 1673 | extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree, |
1736 | fs_info->btree_inode->i_mapping, | 1674 | fs_info->btree_inode->i_mapping); |
1737 | GFP_NOFS); | 1675 | extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree); |
1738 | extent_map_tree_init(&BTRFS_I(fs_info->btree_inode)->extent_tree, | ||
1739 | GFP_NOFS); | ||
1740 | 1676 | ||
1741 | BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops; | 1677 | BTRFS_I(fs_info->btree_inode)->io_tree.ops = &btree_extent_io_ops; |
1742 | 1678 | ||
@@ -1750,9 +1686,9 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1750 | fs_info->block_group_cache_tree = RB_ROOT; | 1686 | fs_info->block_group_cache_tree = RB_ROOT; |
1751 | 1687 | ||
1752 | extent_io_tree_init(&fs_info->freed_extents[0], | 1688 | extent_io_tree_init(&fs_info->freed_extents[0], |
1753 | fs_info->btree_inode->i_mapping, GFP_NOFS); | 1689 | fs_info->btree_inode->i_mapping); |
1754 | extent_io_tree_init(&fs_info->freed_extents[1], | 1690 | extent_io_tree_init(&fs_info->freed_extents[1], |
1755 | fs_info->btree_inode->i_mapping, GFP_NOFS); | 1691 | fs_info->btree_inode->i_mapping); |
1756 | fs_info->pinned_extents = &fs_info->freed_extents[0]; | 1692 | fs_info->pinned_extents = &fs_info->freed_extents[0]; |
1757 | fs_info->do_barriers = 1; | 1693 | fs_info->do_barriers = 1; |
1758 | 1694 | ||
@@ -2194,11 +2130,9 @@ static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate) | |||
2194 | if (uptodate) { | 2130 | if (uptodate) { |
2195 | set_buffer_uptodate(bh); | 2131 | set_buffer_uptodate(bh); |
2196 | } else { | 2132 | } else { |
2197 | if (printk_ratelimit()) { | 2133 | printk_ratelimited(KERN_WARNING "lost page write due to " |
2198 | printk(KERN_WARNING "lost page write due to " | ||
2199 | "I/O error on %s\n", | 2134 | "I/O error on %s\n", |
2200 | bdevname(bh->b_bdev, b)); | 2135 | bdevname(bh->b_bdev, b)); |
2201 | } | ||
2202 | /* note, we dont' set_buffer_write_io_error because we have | 2136 | /* note, we dont' set_buffer_write_io_error because we have |
2203 | * our own ways of dealing with the IO errors | 2137 | * our own ways of dealing with the IO errors |
2204 | */ | 2138 | */ |
@@ -2756,7 +2690,7 @@ int btree_lock_page_hook(struct page *page) | |||
2756 | goto out; | 2690 | goto out; |
2757 | 2691 | ||
2758 | len = page->private >> 2; | 2692 | len = page->private >> 2; |
2759 | eb = find_extent_buffer(io_tree, bytenr, len, GFP_NOFS); | 2693 | eb = find_extent_buffer(io_tree, bytenr, len); |
2760 | if (!eb) | 2694 | if (!eb) |
2761 | goto out; | 2695 | goto out; |
2762 | 2696 | ||
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index aca35af37dbc..a0b610a67aae 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h | |||
@@ -55,36 +55,20 @@ int btrfs_commit_super(struct btrfs_root *root); | |||
55 | int btrfs_error_commit_super(struct btrfs_root *root); | 55 | int btrfs_error_commit_super(struct btrfs_root *root); |
56 | struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, | 56 | struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, |
57 | u64 bytenr, u32 blocksize); | 57 | u64 bytenr, u32 blocksize); |
58 | struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info, | ||
59 | u64 root_objectid); | ||
60 | struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info, | ||
61 | struct btrfs_key *location, | ||
62 | const char *name, int namelen); | ||
63 | struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_root *tree_root, | 58 | struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_root *tree_root, |
64 | struct btrfs_key *location); | 59 | struct btrfs_key *location); |
65 | struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info, | 60 | struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info, |
66 | struct btrfs_key *location); | 61 | struct btrfs_key *location); |
67 | int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info); | 62 | int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info); |
68 | int btrfs_insert_dev_radix(struct btrfs_root *root, | ||
69 | struct block_device *bdev, | ||
70 | u64 device_id, | ||
71 | u64 block_start, | ||
72 | u64 num_blocks); | ||
73 | void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr); | 63 | void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr); |
74 | void __btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr); | 64 | void __btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr); |
75 | int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root); | 65 | int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root); |
76 | void btrfs_mark_buffer_dirty(struct extent_buffer *buf); | 66 | void btrfs_mark_buffer_dirty(struct extent_buffer *buf); |
77 | void btrfs_mark_buffer_dirty_nonblocking(struct extent_buffer *buf); | ||
78 | int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid); | 67 | int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid); |
79 | int btrfs_set_buffer_uptodate(struct extent_buffer *buf); | 68 | int btrfs_set_buffer_uptodate(struct extent_buffer *buf); |
80 | int wait_on_tree_block_writeback(struct btrfs_root *root, | ||
81 | struct extent_buffer *buf); | ||
82 | int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid); | 69 | int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid); |
83 | u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len); | 70 | u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len); |
84 | void btrfs_csum_final(u32 crc, char *result); | 71 | void btrfs_csum_final(u32 crc, char *result); |
85 | int btrfs_open_device(struct btrfs_device *dev); | ||
86 | int btrfs_verify_block_csum(struct btrfs_root *root, | ||
87 | struct extent_buffer *buf); | ||
88 | int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio, | 72 | int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio, |
89 | int metadata); | 73 | int metadata); |
90 | int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, | 74 | int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, |
@@ -92,8 +76,6 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, | |||
92 | unsigned long bio_flags, u64 bio_offset, | 76 | unsigned long bio_flags, u64 bio_offset, |
93 | extent_submit_bio_hook_t *submit_bio_start, | 77 | extent_submit_bio_hook_t *submit_bio_start, |
94 | extent_submit_bio_hook_t *submit_bio_done); | 78 | extent_submit_bio_hook_t *submit_bio_done); |
95 | |||
96 | int btrfs_congested_async(struct btrfs_fs_info *info, int iodone); | ||
97 | unsigned long btrfs_async_submit_limit(struct btrfs_fs_info *info); | 79 | unsigned long btrfs_async_submit_limit(struct btrfs_fs_info *info); |
98 | int btrfs_write_tree_block(struct extent_buffer *buf); | 80 | int btrfs_write_tree_block(struct extent_buffer *buf); |
99 | int btrfs_wait_tree_block_writeback(struct extent_buffer *buf); | 81 | int btrfs_wait_tree_block_writeback(struct extent_buffer *buf); |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 810d1f80b497..98ca149bdbc8 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -94,7 +94,7 @@ static int block_group_bits(struct btrfs_block_group_cache *cache, u64 bits) | |||
94 | return (cache->flags & bits) == bits; | 94 | return (cache->flags & bits) == bits; |
95 | } | 95 | } |
96 | 96 | ||
97 | void btrfs_get_block_group(struct btrfs_block_group_cache *cache) | 97 | static void btrfs_get_block_group(struct btrfs_block_group_cache *cache) |
98 | { | 98 | { |
99 | atomic_inc(&cache->count); | 99 | atomic_inc(&cache->count); |
100 | } | 100 | } |
@@ -380,7 +380,7 @@ again: | |||
380 | break; | 380 | break; |
381 | 381 | ||
382 | caching_ctl->progress = last; | 382 | caching_ctl->progress = last; |
383 | btrfs_release_path(extent_root, path); | 383 | btrfs_release_path(path); |
384 | up_read(&fs_info->extent_commit_sem); | 384 | up_read(&fs_info->extent_commit_sem); |
385 | mutex_unlock(&caching_ctl->mutex); | 385 | mutex_unlock(&caching_ctl->mutex); |
386 | if (btrfs_transaction_in_commit(fs_info)) | 386 | if (btrfs_transaction_in_commit(fs_info)) |
@@ -755,8 +755,12 @@ again: | |||
755 | atomic_inc(&head->node.refs); | 755 | atomic_inc(&head->node.refs); |
756 | spin_unlock(&delayed_refs->lock); | 756 | spin_unlock(&delayed_refs->lock); |
757 | 757 | ||
758 | btrfs_release_path(root->fs_info->extent_root, path); | 758 | btrfs_release_path(path); |
759 | 759 | ||
760 | /* | ||
761 | * Mutex was contended, block until it's released and try | ||
762 | * again | ||
763 | */ | ||
760 | mutex_lock(&head->mutex); | 764 | mutex_lock(&head->mutex); |
761 | mutex_unlock(&head->mutex); | 765 | mutex_unlock(&head->mutex); |
762 | btrfs_put_delayed_ref(&head->node); | 766 | btrfs_put_delayed_ref(&head->node); |
@@ -935,7 +939,7 @@ static int convert_extent_item_v0(struct btrfs_trans_handle *trans, | |||
935 | break; | 939 | break; |
936 | } | 940 | } |
937 | } | 941 | } |
938 | btrfs_release_path(root, path); | 942 | btrfs_release_path(path); |
939 | 943 | ||
940 | if (owner < BTRFS_FIRST_FREE_OBJECTID) | 944 | if (owner < BTRFS_FIRST_FREE_OBJECTID) |
941 | new_size += sizeof(*bi); | 945 | new_size += sizeof(*bi); |
@@ -1043,7 +1047,7 @@ again: | |||
1043 | return 0; | 1047 | return 0; |
1044 | #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 | 1048 | #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 |
1045 | key.type = BTRFS_EXTENT_REF_V0_KEY; | 1049 | key.type = BTRFS_EXTENT_REF_V0_KEY; |
1046 | btrfs_release_path(root, path); | 1050 | btrfs_release_path(path); |
1047 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); | 1051 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); |
1048 | if (ret < 0) { | 1052 | if (ret < 0) { |
1049 | err = ret; | 1053 | err = ret; |
@@ -1081,7 +1085,7 @@ again: | |||
1081 | if (match_extent_data_ref(leaf, ref, root_objectid, | 1085 | if (match_extent_data_ref(leaf, ref, root_objectid, |
1082 | owner, offset)) { | 1086 | owner, offset)) { |
1083 | if (recow) { | 1087 | if (recow) { |
1084 | btrfs_release_path(root, path); | 1088 | btrfs_release_path(path); |
1085 | goto again; | 1089 | goto again; |
1086 | } | 1090 | } |
1087 | err = 0; | 1091 | err = 0; |
@@ -1142,7 +1146,7 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans, | |||
1142 | if (match_extent_data_ref(leaf, ref, root_objectid, | 1146 | if (match_extent_data_ref(leaf, ref, root_objectid, |
1143 | owner, offset)) | 1147 | owner, offset)) |
1144 | break; | 1148 | break; |
1145 | btrfs_release_path(root, path); | 1149 | btrfs_release_path(path); |
1146 | key.offset++; | 1150 | key.offset++; |
1147 | ret = btrfs_insert_empty_item(trans, root, path, &key, | 1151 | ret = btrfs_insert_empty_item(trans, root, path, &key, |
1148 | size); | 1152 | size); |
@@ -1168,7 +1172,7 @@ static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans, | |||
1168 | btrfs_mark_buffer_dirty(leaf); | 1172 | btrfs_mark_buffer_dirty(leaf); |
1169 | ret = 0; | 1173 | ret = 0; |
1170 | fail: | 1174 | fail: |
1171 | btrfs_release_path(root, path); | 1175 | btrfs_release_path(path); |
1172 | return ret; | 1176 | return ret; |
1173 | } | 1177 | } |
1174 | 1178 | ||
@@ -1294,7 +1298,7 @@ static noinline int lookup_tree_block_ref(struct btrfs_trans_handle *trans, | |||
1294 | ret = -ENOENT; | 1298 | ret = -ENOENT; |
1295 | #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 | 1299 | #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 |
1296 | if (ret == -ENOENT && parent) { | 1300 | if (ret == -ENOENT && parent) { |
1297 | btrfs_release_path(root, path); | 1301 | btrfs_release_path(path); |
1298 | key.type = BTRFS_EXTENT_REF_V0_KEY; | 1302 | key.type = BTRFS_EXTENT_REF_V0_KEY; |
1299 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); | 1303 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); |
1300 | if (ret > 0) | 1304 | if (ret > 0) |
@@ -1323,7 +1327,7 @@ static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans, | |||
1323 | } | 1327 | } |
1324 | 1328 | ||
1325 | ret = btrfs_insert_empty_item(trans, root, path, &key, 0); | 1329 | ret = btrfs_insert_empty_item(trans, root, path, &key, 0); |
1326 | btrfs_release_path(root, path); | 1330 | btrfs_release_path(path); |
1327 | return ret; | 1331 | return ret; |
1328 | } | 1332 | } |
1329 | 1333 | ||
@@ -1609,7 +1613,7 @@ static int lookup_extent_backref(struct btrfs_trans_handle *trans, | |||
1609 | if (ret != -ENOENT) | 1613 | if (ret != -ENOENT) |
1610 | return ret; | 1614 | return ret; |
1611 | 1615 | ||
1612 | btrfs_release_path(root, path); | 1616 | btrfs_release_path(path); |
1613 | *ref_ret = NULL; | 1617 | *ref_ret = NULL; |
1614 | 1618 | ||
1615 | if (owner < BTRFS_FIRST_FREE_OBJECTID) { | 1619 | if (owner < BTRFS_FIRST_FREE_OBJECTID) { |
@@ -1863,7 +1867,7 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, | |||
1863 | __run_delayed_extent_op(extent_op, leaf, item); | 1867 | __run_delayed_extent_op(extent_op, leaf, item); |
1864 | 1868 | ||
1865 | btrfs_mark_buffer_dirty(leaf); | 1869 | btrfs_mark_buffer_dirty(leaf); |
1866 | btrfs_release_path(root->fs_info->extent_root, path); | 1870 | btrfs_release_path(path); |
1867 | 1871 | ||
1868 | path->reada = 1; | 1872 | path->reada = 1; |
1869 | path->leave_spinning = 1; | 1873 | path->leave_spinning = 1; |
@@ -2298,6 +2302,10 @@ again: | |||
2298 | atomic_inc(&ref->refs); | 2302 | atomic_inc(&ref->refs); |
2299 | 2303 | ||
2300 | spin_unlock(&delayed_refs->lock); | 2304 | spin_unlock(&delayed_refs->lock); |
2305 | /* | ||
2306 | * Mutex was contended, block until it's | ||
2307 | * released and try again | ||
2308 | */ | ||
2301 | mutex_lock(&head->mutex); | 2309 | mutex_lock(&head->mutex); |
2302 | mutex_unlock(&head->mutex); | 2310 | mutex_unlock(&head->mutex); |
2303 | 2311 | ||
@@ -2362,8 +2370,12 @@ static noinline int check_delayed_ref(struct btrfs_trans_handle *trans, | |||
2362 | atomic_inc(&head->node.refs); | 2370 | atomic_inc(&head->node.refs); |
2363 | spin_unlock(&delayed_refs->lock); | 2371 | spin_unlock(&delayed_refs->lock); |
2364 | 2372 | ||
2365 | btrfs_release_path(root->fs_info->extent_root, path); | 2373 | btrfs_release_path(path); |
2366 | 2374 | ||
2375 | /* | ||
2376 | * Mutex was contended, block until it's released and let | ||
2377 | * caller try again | ||
2378 | */ | ||
2367 | mutex_lock(&head->mutex); | 2379 | mutex_lock(&head->mutex); |
2368 | mutex_unlock(&head->mutex); | 2380 | mutex_unlock(&head->mutex); |
2369 | btrfs_put_delayed_ref(&head->node); | 2381 | btrfs_put_delayed_ref(&head->node); |
@@ -2511,126 +2523,6 @@ out: | |||
2511 | return ret; | 2523 | return ret; |
2512 | } | 2524 | } |
2513 | 2525 | ||
2514 | #if 0 | ||
2515 | int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, | ||
2516 | struct extent_buffer *buf, u32 nr_extents) | ||
2517 | { | ||
2518 | struct btrfs_key key; | ||
2519 | struct btrfs_file_extent_item *fi; | ||
2520 | u64 root_gen; | ||
2521 | u32 nritems; | ||
2522 | int i; | ||
2523 | int level; | ||
2524 | int ret = 0; | ||
2525 | int shared = 0; | ||
2526 | |||
2527 | if (!root->ref_cows) | ||
2528 | return 0; | ||
2529 | |||
2530 | if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { | ||
2531 | shared = 0; | ||
2532 | root_gen = root->root_key.offset; | ||
2533 | } else { | ||
2534 | shared = 1; | ||
2535 | root_gen = trans->transid - 1; | ||
2536 | } | ||
2537 | |||
2538 | level = btrfs_header_level(buf); | ||
2539 | nritems = btrfs_header_nritems(buf); | ||
2540 | |||
2541 | if (level == 0) { | ||
2542 | struct btrfs_leaf_ref *ref; | ||
2543 | struct btrfs_extent_info *info; | ||
2544 | |||
2545 | ref = btrfs_alloc_leaf_ref(root, nr_extents); | ||
2546 | if (!ref) { | ||
2547 | ret = -ENOMEM; | ||
2548 | goto out; | ||
2549 | } | ||
2550 | |||
2551 | ref->root_gen = root_gen; | ||
2552 | ref->bytenr = buf->start; | ||
2553 | ref->owner = btrfs_header_owner(buf); | ||
2554 | ref->generation = btrfs_header_generation(buf); | ||
2555 | ref->nritems = nr_extents; | ||
2556 | info = ref->extents; | ||
2557 | |||
2558 | for (i = 0; nr_extents > 0 && i < nritems; i++) { | ||
2559 | u64 disk_bytenr; | ||
2560 | btrfs_item_key_to_cpu(buf, &key, i); | ||
2561 | if (btrfs_key_type(&key) != BTRFS_EXTENT_DATA_KEY) | ||
2562 | continue; | ||
2563 | fi = btrfs_item_ptr(buf, i, | ||
2564 | struct btrfs_file_extent_item); | ||
2565 | if (btrfs_file_extent_type(buf, fi) == | ||
2566 | BTRFS_FILE_EXTENT_INLINE) | ||
2567 | continue; | ||
2568 | disk_bytenr = btrfs_file_extent_disk_bytenr(buf, fi); | ||
2569 | if (disk_bytenr == 0) | ||
2570 | continue; | ||
2571 | |||
2572 | info->bytenr = disk_bytenr; | ||
2573 | info->num_bytes = | ||
2574 | btrfs_file_extent_disk_num_bytes(buf, fi); | ||
2575 | info->objectid = key.objectid; | ||
2576 | info->offset = key.offset; | ||
2577 | info++; | ||
2578 | } | ||
2579 | |||
2580 | ret = btrfs_add_leaf_ref(root, ref, shared); | ||
2581 | if (ret == -EEXIST && shared) { | ||
2582 | struct btrfs_leaf_ref *old; | ||
2583 | old = btrfs_lookup_leaf_ref(root, ref->bytenr); | ||
2584 | BUG_ON(!old); | ||
2585 | btrfs_remove_leaf_ref(root, old); | ||
2586 | btrfs_free_leaf_ref(root, old); | ||
2587 | ret = btrfs_add_leaf_ref(root, ref, shared); | ||
2588 | } | ||
2589 | WARN_ON(ret); | ||
2590 | btrfs_free_leaf_ref(root, ref); | ||
2591 | } | ||
2592 | out: | ||
2593 | return ret; | ||
2594 | } | ||
2595 | |||
2596 | /* when a block goes through cow, we update the reference counts of | ||
2597 | * everything that block points to. The internal pointers of the block | ||
2598 | * can be in just about any order, and it is likely to have clusters of | ||
2599 | * things that are close together and clusters of things that are not. | ||
2600 | * | ||
2601 | * To help reduce the seeks that come with updating all of these reference | ||
2602 | * counts, sort them by byte number before actual updates are done. | ||
2603 | * | ||
2604 | * struct refsort is used to match byte number to slot in the btree block. | ||
2605 | * we sort based on the byte number and then use the slot to actually | ||
2606 | * find the item. | ||
2607 | * | ||
2608 | * struct refsort is smaller than strcut btrfs_item and smaller than | ||
2609 | * struct btrfs_key_ptr. Since we're currently limited to the page size | ||
2610 | * for a btree block, there's no way for a kmalloc of refsorts for a | ||
2611 | * single node to be bigger than a page. | ||
2612 | */ | ||
2613 | struct refsort { | ||
2614 | u64 bytenr; | ||
2615 | u32 slot; | ||
2616 | }; | ||
2617 | |||
2618 | /* | ||
2619 | * for passing into sort() | ||
2620 | */ | ||
2621 | static int refsort_cmp(const void *a_void, const void *b_void) | ||
2622 | { | ||
2623 | const struct refsort *a = a_void; | ||
2624 | const struct refsort *b = b_void; | ||
2625 | |||
2626 | if (a->bytenr < b->bytenr) | ||
2627 | return -1; | ||
2628 | if (a->bytenr > b->bytenr) | ||
2629 | return 1; | ||
2630 | return 0; | ||
2631 | } | ||
2632 | #endif | ||
2633 | |||
2634 | static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, | 2526 | static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, |
2635 | struct btrfs_root *root, | 2527 | struct btrfs_root *root, |
2636 | struct extent_buffer *buf, | 2528 | struct extent_buffer *buf, |
@@ -2733,7 +2625,7 @@ static int write_one_cache_group(struct btrfs_trans_handle *trans, | |||
2733 | bi = btrfs_item_ptr_offset(leaf, path->slots[0]); | 2625 | bi = btrfs_item_ptr_offset(leaf, path->slots[0]); |
2734 | write_extent_buffer(leaf, &cache->item, bi, sizeof(cache->item)); | 2626 | write_extent_buffer(leaf, &cache->item, bi, sizeof(cache->item)); |
2735 | btrfs_mark_buffer_dirty(leaf); | 2627 | btrfs_mark_buffer_dirty(leaf); |
2736 | btrfs_release_path(extent_root, path); | 2628 | btrfs_release_path(path); |
2737 | fail: | 2629 | fail: |
2738 | if (ret) | 2630 | if (ret) |
2739 | return ret; | 2631 | return ret; |
@@ -2786,7 +2678,7 @@ again: | |||
2786 | inode = lookup_free_space_inode(root, block_group, path); | 2678 | inode = lookup_free_space_inode(root, block_group, path); |
2787 | if (IS_ERR(inode) && PTR_ERR(inode) != -ENOENT) { | 2679 | if (IS_ERR(inode) && PTR_ERR(inode) != -ENOENT) { |
2788 | ret = PTR_ERR(inode); | 2680 | ret = PTR_ERR(inode); |
2789 | btrfs_release_path(root, path); | 2681 | btrfs_release_path(path); |
2790 | goto out; | 2682 | goto out; |
2791 | } | 2683 | } |
2792 | 2684 | ||
@@ -2855,7 +2747,7 @@ again: | |||
2855 | out_put: | 2747 | out_put: |
2856 | iput(inode); | 2748 | iput(inode); |
2857 | out_free: | 2749 | out_free: |
2858 | btrfs_release_path(root, path); | 2750 | btrfs_release_path(path); |
2859 | out: | 2751 | out: |
2860 | spin_lock(&block_group->lock); | 2752 | spin_lock(&block_group->lock); |
2861 | block_group->disk_cache_state = dcs; | 2753 | block_group->disk_cache_state = dcs; |
@@ -3213,18 +3105,6 @@ commit_trans: | |||
3213 | goto again; | 3105 | goto again; |
3214 | } | 3106 | } |
3215 | 3107 | ||
3216 | #if 0 /* I hope we never need this code again, just in case */ | ||
3217 | printk(KERN_ERR "no space left, need %llu, %llu bytes_used, " | ||
3218 | "%llu bytes_reserved, " "%llu bytes_pinned, " | ||
3219 | "%llu bytes_readonly, %llu may use %llu total\n", | ||
3220 | (unsigned long long)bytes, | ||
3221 | (unsigned long long)data_sinfo->bytes_used, | ||
3222 | (unsigned long long)data_sinfo->bytes_reserved, | ||
3223 | (unsigned long long)data_sinfo->bytes_pinned, | ||
3224 | (unsigned long long)data_sinfo->bytes_readonly, | ||
3225 | (unsigned long long)data_sinfo->bytes_may_use, | ||
3226 | (unsigned long long)data_sinfo->total_bytes); | ||
3227 | #endif | ||
3228 | return -ENOSPC; | 3108 | return -ENOSPC; |
3229 | } | 3109 | } |
3230 | data_sinfo->bytes_may_use += bytes; | 3110 | data_sinfo->bytes_may_use += bytes; |
@@ -3653,8 +3533,8 @@ static void block_rsv_add_bytes(struct btrfs_block_rsv *block_rsv, | |||
3653 | spin_unlock(&block_rsv->lock); | 3533 | spin_unlock(&block_rsv->lock); |
3654 | } | 3534 | } |
3655 | 3535 | ||
3656 | void block_rsv_release_bytes(struct btrfs_block_rsv *block_rsv, | 3536 | static void block_rsv_release_bytes(struct btrfs_block_rsv *block_rsv, |
3657 | struct btrfs_block_rsv *dest, u64 num_bytes) | 3537 | struct btrfs_block_rsv *dest, u64 num_bytes) |
3658 | { | 3538 | { |
3659 | struct btrfs_space_info *space_info = block_rsv->space_info; | 3539 | struct btrfs_space_info *space_info = block_rsv->space_info; |
3660 | 3540 | ||
@@ -3857,23 +3737,7 @@ static u64 calc_global_metadata_size(struct btrfs_fs_info *fs_info) | |||
3857 | u64 meta_used; | 3737 | u64 meta_used; |
3858 | u64 data_used; | 3738 | u64 data_used; |
3859 | int csum_size = btrfs_super_csum_size(&fs_info->super_copy); | 3739 | int csum_size = btrfs_super_csum_size(&fs_info->super_copy); |
3860 | #if 0 | ||
3861 | /* | ||
3862 | * per tree used space accounting can be inaccuracy, so we | ||
3863 | * can't rely on it. | ||
3864 | */ | ||
3865 | spin_lock(&fs_info->extent_root->accounting_lock); | ||
3866 | num_bytes = btrfs_root_used(&fs_info->extent_root->root_item); | ||
3867 | spin_unlock(&fs_info->extent_root->accounting_lock); | ||
3868 | |||
3869 | spin_lock(&fs_info->csum_root->accounting_lock); | ||
3870 | num_bytes += btrfs_root_used(&fs_info->csum_root->root_item); | ||
3871 | spin_unlock(&fs_info->csum_root->accounting_lock); | ||
3872 | 3740 | ||
3873 | spin_lock(&fs_info->tree_root->accounting_lock); | ||
3874 | num_bytes += btrfs_root_used(&fs_info->tree_root->root_item); | ||
3875 | spin_unlock(&fs_info->tree_root->accounting_lock); | ||
3876 | #endif | ||
3877 | sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_DATA); | 3741 | sinfo = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_DATA); |
3878 | spin_lock(&sinfo->lock); | 3742 | spin_lock(&sinfo->lock); |
3879 | data_used = sinfo->bytes_used; | 3743 | data_used = sinfo->bytes_used; |
@@ -3926,10 +3790,7 @@ static void update_global_block_rsv(struct btrfs_fs_info *fs_info) | |||
3926 | block_rsv->reserved = block_rsv->size; | 3790 | block_rsv->reserved = block_rsv->size; |
3927 | block_rsv->full = 1; | 3791 | block_rsv->full = 1; |
3928 | } | 3792 | } |
3929 | #if 0 | 3793 | |
3930 | printk(KERN_INFO"global block rsv size %llu reserved %llu\n", | ||
3931 | block_rsv->size, block_rsv->reserved); | ||
3932 | #endif | ||
3933 | spin_unlock(&sinfo->lock); | 3794 | spin_unlock(&sinfo->lock); |
3934 | spin_unlock(&block_rsv->lock); | 3795 | spin_unlock(&block_rsv->lock); |
3935 | } | 3796 | } |
@@ -4537,7 +4398,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
4537 | NULL, refs_to_drop, | 4398 | NULL, refs_to_drop, |
4538 | is_data); | 4399 | is_data); |
4539 | BUG_ON(ret); | 4400 | BUG_ON(ret); |
4540 | btrfs_release_path(extent_root, path); | 4401 | btrfs_release_path(path); |
4541 | path->leave_spinning = 1; | 4402 | path->leave_spinning = 1; |
4542 | 4403 | ||
4543 | key.objectid = bytenr; | 4404 | key.objectid = bytenr; |
@@ -4576,7 +4437,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
4576 | owner_objectid, 0); | 4437 | owner_objectid, 0); |
4577 | BUG_ON(ret < 0); | 4438 | BUG_ON(ret < 0); |
4578 | 4439 | ||
4579 | btrfs_release_path(extent_root, path); | 4440 | btrfs_release_path(path); |
4580 | path->leave_spinning = 1; | 4441 | path->leave_spinning = 1; |
4581 | 4442 | ||
4582 | key.objectid = bytenr; | 4443 | key.objectid = bytenr; |
@@ -4646,7 +4507,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
4646 | ret = btrfs_del_items(trans, extent_root, path, path->slots[0], | 4507 | ret = btrfs_del_items(trans, extent_root, path, path->slots[0], |
4647 | num_to_del); | 4508 | num_to_del); |
4648 | BUG_ON(ret); | 4509 | BUG_ON(ret); |
4649 | btrfs_release_path(extent_root, path); | 4510 | btrfs_release_path(path); |
4650 | 4511 | ||
4651 | if (is_data) { | 4512 | if (is_data) { |
4652 | ret = btrfs_del_csums(trans, root, bytenr, num_bytes); | 4513 | ret = btrfs_del_csums(trans, root, bytenr, num_bytes); |
@@ -6476,7 +6337,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, | |||
6476 | trans->block_rsv = block_rsv; | 6337 | trans->block_rsv = block_rsv; |
6477 | } | 6338 | } |
6478 | } | 6339 | } |
6479 | btrfs_release_path(root, path); | 6340 | btrfs_release_path(path); |
6480 | BUG_ON(err); | 6341 | BUG_ON(err); |
6481 | 6342 | ||
6482 | ret = btrfs_del_root(trans, tree_root, &root->root_key); | 6343 | ret = btrfs_del_root(trans, tree_root, &root->root_key); |
@@ -6580,1514 +6441,6 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans, | |||
6580 | return ret; | 6441 | return ret; |
6581 | } | 6442 | } |
6582 | 6443 | ||
6583 | #if 0 | ||
6584 | static unsigned long calc_ra(unsigned long start, unsigned long last, | ||
6585 | unsigned long nr) | ||
6586 | { | ||
6587 | return min(last, start + nr - 1); | ||
6588 | } | ||
6589 | |||
6590 | static noinline int relocate_inode_pages(struct inode *inode, u64 start, | ||
6591 | u64 len) | ||
6592 | { | ||
6593 | u64 page_start; | ||
6594 | u64 page_end; | ||
6595 | unsigned long first_index; | ||
6596 | unsigned long last_index; | ||
6597 | unsigned long i; | ||
6598 | struct page *page; | ||
6599 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; | ||
6600 | struct file_ra_state *ra; | ||
6601 | struct btrfs_ordered_extent *ordered; | ||
6602 | unsigned int total_read = 0; | ||
6603 | unsigned int total_dirty = 0; | ||
6604 | int ret = 0; | ||
6605 | |||
6606 | ra = kzalloc(sizeof(*ra), GFP_NOFS); | ||
6607 | if (!ra) | ||
6608 | return -ENOMEM; | ||
6609 | |||
6610 | mutex_lock(&inode->i_mutex); | ||
6611 | first_index = start >> PAGE_CACHE_SHIFT; | ||
6612 | last_index = (start + len - 1) >> PAGE_CACHE_SHIFT; | ||
6613 | |||
6614 | /* make sure the dirty trick played by the caller work */ | ||
6615 | ret = invalidate_inode_pages2_range(inode->i_mapping, | ||
6616 | first_index, last_index); | ||
6617 | if (ret) | ||
6618 | goto out_unlock; | ||
6619 | |||
6620 | file_ra_state_init(ra, inode->i_mapping); | ||
6621 | |||
6622 | for (i = first_index ; i <= last_index; i++) { | ||
6623 | if (total_read % ra->ra_pages == 0) { | ||
6624 | btrfs_force_ra(inode->i_mapping, ra, NULL, i, | ||
6625 | calc_ra(i, last_index, ra->ra_pages)); | ||
6626 | } | ||
6627 | total_read++; | ||
6628 | again: | ||
6629 | if (((u64)i << PAGE_CACHE_SHIFT) > i_size_read(inode)) | ||
6630 | BUG_ON(1); | ||
6631 | page = grab_cache_page(inode->i_mapping, i); | ||
6632 | if (!page) { | ||
6633 | ret = -ENOMEM; | ||
6634 | goto out_unlock; | ||
6635 | } | ||
6636 | if (!PageUptodate(page)) { | ||
6637 | btrfs_readpage(NULL, page); | ||
6638 | lock_page(page); | ||
6639 | if (!PageUptodate(page)) { | ||
6640 | unlock_page(page); | ||
6641 | page_cache_release(page); | ||
6642 | ret = -EIO; | ||
6643 | goto out_unlock; | ||
6644 | } | ||
6645 | } | ||
6646 | wait_on_page_writeback(page); | ||
6647 | |||
6648 | page_start = (u64)page->index << PAGE_CACHE_SHIFT; | ||
6649 | page_end = page_start + PAGE_CACHE_SIZE - 1; | ||
6650 | lock_extent(io_tree, page_start, page_end, GFP_NOFS); | ||
6651 | |||
6652 | ordered = btrfs_lookup_ordered_extent(inode, page_start); | ||
6653 | if (ordered) { | ||
6654 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | ||
6655 | unlock_page(page); | ||
6656 | page_cache_release(page); | ||
6657 | btrfs_start_ordered_extent(inode, ordered, 1); | ||
6658 | btrfs_put_ordered_extent(ordered); | ||
6659 | goto again; | ||
6660 | } | ||
6661 | set_page_extent_mapped(page); | ||
6662 | |||
6663 | if (i == first_index) | ||
6664 | set_extent_bits(io_tree, page_start, page_end, | ||
6665 | EXTENT_BOUNDARY, GFP_NOFS); | ||
6666 | btrfs_set_extent_delalloc(inode, page_start, page_end); | ||
6667 | |||
6668 | set_page_dirty(page); | ||
6669 | total_dirty++; | ||
6670 | |||
6671 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | ||
6672 | unlock_page(page); | ||
6673 | page_cache_release(page); | ||
6674 | } | ||
6675 | |||
6676 | out_unlock: | ||
6677 | kfree(ra); | ||
6678 | mutex_unlock(&inode->i_mutex); | ||
6679 | balance_dirty_pages_ratelimited_nr(inode->i_mapping, total_dirty); | ||
6680 | return ret; | ||
6681 | } | ||
6682 | |||
6683 | static noinline int relocate_data_extent(struct inode *reloc_inode, | ||
6684 | struct btrfs_key *extent_key, | ||
6685 | u64 offset) | ||
6686 | { | ||
6687 | struct btrfs_root *root = BTRFS_I(reloc_inode)->root; | ||
6688 | struct extent_map_tree *em_tree = &BTRFS_I(reloc_inode)->extent_tree; | ||
6689 | struct extent_map *em; | ||
6690 | u64 start = extent_key->objectid - offset; | ||
6691 | u64 end = start + extent_key->offset - 1; | ||
6692 | |||
6693 | em = alloc_extent_map(GFP_NOFS); | ||
6694 | BUG_ON(!em); | ||
6695 | |||
6696 | em->start = start; | ||
6697 | em->len = extent_key->offset; | ||
6698 | em->block_len = extent_key->offset; | ||
6699 | em->block_start = extent_key->objectid; | ||
6700 | em->bdev = root->fs_info->fs_devices->latest_bdev; | ||
6701 | set_bit(EXTENT_FLAG_PINNED, &em->flags); | ||
6702 | |||
6703 | /* setup extent map to cheat btrfs_readpage */ | ||
6704 | lock_extent(&BTRFS_I(reloc_inode)->io_tree, start, end, GFP_NOFS); | ||
6705 | while (1) { | ||
6706 | int ret; | ||
6707 | write_lock(&em_tree->lock); | ||
6708 | ret = add_extent_mapping(em_tree, em); | ||
6709 | write_unlock(&em_tree->lock); | ||
6710 | if (ret != -EEXIST) { | ||
6711 | free_extent_map(em); | ||
6712 | break; | ||
6713 | } | ||
6714 | btrfs_drop_extent_cache(reloc_inode, start, end, 0); | ||
6715 | } | ||
6716 | unlock_extent(&BTRFS_I(reloc_inode)->io_tree, start, end, GFP_NOFS); | ||
6717 | |||
6718 | return relocate_inode_pages(reloc_inode, start, extent_key->offset); | ||
6719 | } | ||
6720 | |||
6721 | struct btrfs_ref_path { | ||
6722 | u64 extent_start; | ||
6723 | u64 nodes[BTRFS_MAX_LEVEL]; | ||
6724 | u64 root_objectid; | ||
6725 | u64 root_generation; | ||
6726 | u64 owner_objectid; | ||
6727 | u32 num_refs; | ||
6728 | int lowest_level; | ||
6729 | int current_level; | ||
6730 | int shared_level; | ||
6731 | |||
6732 | struct btrfs_key node_keys[BTRFS_MAX_LEVEL]; | ||
6733 | u64 new_nodes[BTRFS_MAX_LEVEL]; | ||
6734 | }; | ||
6735 | |||
6736 | struct disk_extent { | ||
6737 | u64 ram_bytes; | ||
6738 | u64 disk_bytenr; | ||
6739 | u64 disk_num_bytes; | ||
6740 | u64 offset; | ||
6741 | u64 num_bytes; | ||
6742 | u8 compression; | ||
6743 | u8 encryption; | ||
6744 | u16 other_encoding; | ||
6745 | }; | ||
6746 | |||
6747 | static int is_cowonly_root(u64 root_objectid) | ||
6748 | { | ||
6749 | if (root_objectid == BTRFS_ROOT_TREE_OBJECTID || | ||
6750 | root_objectid == BTRFS_EXTENT_TREE_OBJECTID || | ||
6751 | root_objectid == BTRFS_CHUNK_TREE_OBJECTID || | ||
6752 | root_objectid == BTRFS_DEV_TREE_OBJECTID || | ||
6753 | root_objectid == BTRFS_TREE_LOG_OBJECTID || | ||
6754 | root_objectid == BTRFS_CSUM_TREE_OBJECTID) | ||
6755 | return 1; | ||
6756 | return 0; | ||
6757 | } | ||
6758 | |||
6759 | static noinline int __next_ref_path(struct btrfs_trans_handle *trans, | ||
6760 | struct btrfs_root *extent_root, | ||
6761 | struct btrfs_ref_path *ref_path, | ||
6762 | int first_time) | ||
6763 | { | ||
6764 | struct extent_buffer *leaf; | ||
6765 | struct btrfs_path *path; | ||
6766 | struct btrfs_extent_ref *ref; | ||
6767 | struct btrfs_key key; | ||
6768 | struct btrfs_key found_key; | ||
6769 | u64 bytenr; | ||
6770 | u32 nritems; | ||
6771 | int level; | ||
6772 | int ret = 1; | ||
6773 | |||
6774 | path = btrfs_alloc_path(); | ||
6775 | if (!path) | ||
6776 | return -ENOMEM; | ||
6777 | |||
6778 | if (first_time) { | ||
6779 | ref_path->lowest_level = -1; | ||
6780 | ref_path->current_level = -1; | ||
6781 | ref_path->shared_level = -1; | ||
6782 | goto walk_up; | ||
6783 | } | ||
6784 | walk_down: | ||
6785 | level = ref_path->current_level - 1; | ||
6786 | while (level >= -1) { | ||
6787 | u64 parent; | ||
6788 | if (level < ref_path->lowest_level) | ||
6789 | break; | ||
6790 | |||
6791 | if (level >= 0) | ||
6792 | bytenr = ref_path->nodes[level]; | ||
6793 | else | ||
6794 | bytenr = ref_path->extent_start; | ||
6795 | BUG_ON(bytenr == 0); | ||
6796 | |||
6797 | parent = ref_path->nodes[level + 1]; | ||
6798 | ref_path->nodes[level + 1] = 0; | ||
6799 | ref_path->current_level = level; | ||
6800 | BUG_ON(parent == 0); | ||
6801 | |||
6802 | key.objectid = bytenr; | ||
6803 | key.offset = parent + 1; | ||
6804 | key.type = BTRFS_EXTENT_REF_KEY; | ||
6805 | |||
6806 | ret = btrfs_search_slot(trans, extent_root, &key, path, 0, 0); | ||
6807 | if (ret < 0) | ||
6808 | goto out; | ||
6809 | BUG_ON(ret == 0); | ||
6810 | |||
6811 | leaf = path->nodes[0]; | ||
6812 | nritems = btrfs_header_nritems(leaf); | ||
6813 | if (path->slots[0] >= nritems) { | ||
6814 | ret = btrfs_next_leaf(extent_root, path); | ||
6815 | if (ret < 0) | ||
6816 | goto out; | ||
6817 | if (ret > 0) | ||
6818 | goto next; | ||
6819 | leaf = path->nodes[0]; | ||
6820 | } | ||
6821 | |||
6822 | btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); | ||
6823 | if (found_key.objectid == bytenr && | ||
6824 | found_key.type == BTRFS_EXTENT_REF_KEY) { | ||
6825 | if (level < ref_path->shared_level) | ||
6826 | ref_path->shared_level = level; | ||
6827 | goto found; | ||
6828 | } | ||
6829 | next: | ||
6830 | level--; | ||
6831 | btrfs_release_path(extent_root, path); | ||
6832 | cond_resched(); | ||
6833 | } | ||
6834 | /* reached lowest level */ | ||
6835 | ret = 1; | ||
6836 | goto out; | ||
6837 | walk_up: | ||
6838 | level = ref_path->current_level; | ||
6839 | while (level < BTRFS_MAX_LEVEL - 1) { | ||
6840 | u64 ref_objectid; | ||
6841 | |||
6842 | if (level >= 0) | ||
6843 | bytenr = ref_path->nodes[level]; | ||
6844 | else | ||
6845 | bytenr = ref_path->extent_start; | ||
6846 | |||
6847 | BUG_ON(bytenr == 0); | ||
6848 | |||
6849 | key.objectid = bytenr; | ||
6850 | key.offset = 0; | ||
6851 | key.type = BTRFS_EXTENT_REF_KEY; | ||
6852 | |||
6853 | ret = btrfs_search_slot(trans, extent_root, &key, path, 0, 0); | ||
6854 | if (ret < 0) | ||
6855 | goto out; | ||
6856 | |||
6857 | leaf = path->nodes[0]; | ||
6858 | nritems = btrfs_header_nritems(leaf); | ||
6859 | if (path->slots[0] >= nritems) { | ||
6860 | ret = btrfs_next_leaf(extent_root, path); | ||
6861 | if (ret < 0) | ||
6862 | goto out; | ||
6863 | if (ret > 0) { | ||
6864 | /* the extent was freed by someone */ | ||
6865 | if (ref_path->lowest_level == level) | ||
6866 | goto out; | ||
6867 | btrfs_release_path(extent_root, path); | ||
6868 | goto walk_down; | ||
6869 | } | ||
6870 | leaf = path->nodes[0]; | ||
6871 | } | ||
6872 | |||
6873 | btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); | ||
6874 | if (found_key.objectid != bytenr || | ||
6875 | found_key.type != BTRFS_EXTENT_REF_KEY) { | ||
6876 | /* the extent was freed by someone */ | ||
6877 | if (ref_path->lowest_level == level) { | ||
6878 | ret = 1; | ||
6879 | goto out; | ||
6880 | } | ||
6881 | btrfs_release_path(extent_root, path); | ||
6882 | goto walk_down; | ||
6883 | } | ||
6884 | found: | ||
6885 | ref = btrfs_item_ptr(leaf, path->slots[0], | ||
6886 | struct btrfs_extent_ref); | ||
6887 | ref_objectid = btrfs_ref_objectid(leaf, ref); | ||
6888 | if (ref_objectid < BTRFS_FIRST_FREE_OBJECTID) { | ||
6889 | if (first_time) { | ||
6890 | level = (int)ref_objectid; | ||
6891 | BUG_ON(level >= BTRFS_MAX_LEVEL); | ||
6892 | ref_path->lowest_level = level; | ||
6893 | ref_path->current_level = level; | ||
6894 | ref_path->nodes[level] = bytenr; | ||
6895 | } else { | ||
6896 | WARN_ON(ref_objectid != level); | ||
6897 | } | ||
6898 | } else { | ||
6899 | WARN_ON(level != -1); | ||
6900 | } | ||
6901 | first_time = 0; | ||
6902 | |||
6903 | if (ref_path->lowest_level == level) { | ||
6904 | ref_path->owner_objectid = ref_objectid; | ||
6905 | ref_path->num_refs = btrfs_ref_num_refs(leaf, ref); | ||
6906 | } | ||
6907 | |||
6908 | /* | ||
6909 | * the block is tree root or the block isn't in reference | ||
6910 | * counted tree. | ||
6911 | */ | ||
6912 | if (found_key.objectid == found_key.offset || | ||
6913 | is_cowonly_root(btrfs_ref_root(leaf, ref))) { | ||
6914 | ref_path->root_objectid = btrfs_ref_root(leaf, ref); | ||
6915 | ref_path->root_generation = | ||
6916 | btrfs_ref_generation(leaf, ref); | ||
6917 | if (level < 0) { | ||
6918 | /* special reference from the tree log */ | ||
6919 | ref_path->nodes[0] = found_key.offset; | ||
6920 | ref_path->current_level = 0; | ||
6921 | } | ||
6922 | ret = 0; | ||
6923 | goto out; | ||
6924 | } | ||
6925 | |||
6926 | level++; | ||
6927 | BUG_ON(ref_path->nodes[level] != 0); | ||
6928 | ref_path->nodes[level] = found_key.offset; | ||
6929 | ref_path->current_level = level; | ||
6930 | |||
6931 | /* | ||
6932 | * the reference was created in the running transaction, | ||
6933 | * no need to continue walking up. | ||
6934 | */ | ||
6935 | if (btrfs_ref_generation(leaf, ref) == trans->transid) { | ||
6936 | ref_path->root_objectid = btrfs_ref_root(leaf, ref); | ||
6937 | ref_path->root_generation = | ||
6938 | btrfs_ref_generation(leaf, ref); | ||
6939 | ret = 0; | ||
6940 | goto out; | ||
6941 | } | ||
6942 | |||
6943 | btrfs_release_path(extent_root, path); | ||
6944 | cond_resched(); | ||
6945 | } | ||
6946 | /* reached max tree level, but no tree root found. */ | ||
6947 | BUG(); | ||
6948 | out: | ||
6949 | btrfs_free_path(path); | ||
6950 | return ret; | ||
6951 | } | ||
6952 | |||
6953 | static int btrfs_first_ref_path(struct btrfs_trans_handle *trans, | ||
6954 | struct btrfs_root *extent_root, | ||
6955 | struct btrfs_ref_path *ref_path, | ||
6956 | u64 extent_start) | ||
6957 | { | ||
6958 | memset(ref_path, 0, sizeof(*ref_path)); | ||
6959 | ref_path->extent_start = extent_start; | ||
6960 | |||
6961 | return __next_ref_path(trans, extent_root, ref_path, 1); | ||
6962 | } | ||
6963 | |||
6964 | static int btrfs_next_ref_path(struct btrfs_trans_handle *trans, | ||
6965 | struct btrfs_root *extent_root, | ||
6966 | struct btrfs_ref_path *ref_path) | ||
6967 | { | ||
6968 | return __next_ref_path(trans, extent_root, ref_path, 0); | ||
6969 | } | ||
6970 | |||
6971 | static noinline int get_new_locations(struct inode *reloc_inode, | ||
6972 | struct btrfs_key *extent_key, | ||
6973 | u64 offset, int no_fragment, | ||
6974 | struct disk_extent **extents, | ||
6975 | int *nr_extents) | ||
6976 | { | ||
6977 | struct btrfs_root *root = BTRFS_I(reloc_inode)->root; | ||
6978 | struct btrfs_path *path; | ||
6979 | struct btrfs_file_extent_item *fi; | ||
6980 | struct extent_buffer *leaf; | ||
6981 | struct disk_extent *exts = *extents; | ||
6982 | struct btrfs_key found_key; | ||
6983 | u64 cur_pos; | ||
6984 | u64 last_byte; | ||
6985 | u32 nritems; | ||
6986 | int nr = 0; | ||
6987 | int max = *nr_extents; | ||
6988 | int ret; | ||
6989 | |||
6990 | WARN_ON(!no_fragment && *extents); | ||
6991 | if (!exts) { | ||
6992 | max = 1; | ||
6993 | exts = kmalloc(sizeof(*exts) * max, GFP_NOFS); | ||
6994 | if (!exts) | ||
6995 | return -ENOMEM; | ||
6996 | } | ||
6997 | |||
6998 | path = btrfs_alloc_path(); | ||
6999 | if (!path) { | ||
7000 | if (exts != *extents) | ||
7001 | kfree(exts); | ||
7002 | return -ENOMEM; | ||
7003 | } | ||
7004 | |||
7005 | cur_pos = extent_key->objectid - offset; | ||
7006 | last_byte = extent_key->objectid + extent_key->offset; | ||
7007 | ret = btrfs_lookup_file_extent(NULL, root, path, | ||
7008 | btrfs_ino(reloc_inode), cur_pos, 0); | ||
7009 | if (ret < 0) | ||
7010 | goto out; | ||
7011 | if (ret > 0) { | ||
7012 | ret = -ENOENT; | ||
7013 | goto out; | ||
7014 | } | ||
7015 | |||
7016 | while (1) { | ||
7017 | leaf = path->nodes[0]; | ||
7018 | nritems = btrfs_header_nritems(leaf); | ||
7019 | if (path->slots[0] >= nritems) { | ||
7020 | ret = btrfs_next_leaf(root, path); | ||
7021 | if (ret < 0) | ||
7022 | goto out; | ||
7023 | if (ret > 0) | ||
7024 | break; | ||
7025 | leaf = path->nodes[0]; | ||
7026 | } | ||
7027 | |||
7028 | btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); | ||
7029 | if (found_key.offset != cur_pos || | ||
7030 | found_key.type != BTRFS_EXTENT_DATA_KEY || | ||
7031 | found_key.objectid != btrfs_ino(reloc_inode)) | ||
7032 | break; | ||
7033 | |||
7034 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
7035 | struct btrfs_file_extent_item); | ||
7036 | if (btrfs_file_extent_type(leaf, fi) != | ||
7037 | BTRFS_FILE_EXTENT_REG || | ||
7038 | btrfs_file_extent_disk_bytenr(leaf, fi) == 0) | ||
7039 | break; | ||
7040 | |||
7041 | if (nr == max) { | ||
7042 | struct disk_extent *old = exts; | ||
7043 | max *= 2; | ||
7044 | exts = kzalloc(sizeof(*exts) * max, GFP_NOFS); | ||
7045 | if (!exts) { | ||
7046 | ret = -ENOMEM; | ||
7047 | goto out; | ||
7048 | } | ||
7049 | memcpy(exts, old, sizeof(*exts) * nr); | ||
7050 | if (old != *extents) | ||
7051 | kfree(old); | ||
7052 | } | ||
7053 | |||
7054 | exts[nr].disk_bytenr = | ||
7055 | btrfs_file_extent_disk_bytenr(leaf, fi); | ||
7056 | exts[nr].disk_num_bytes = | ||
7057 | btrfs_file_extent_disk_num_bytes(leaf, fi); | ||
7058 | exts[nr].offset = btrfs_file_extent_offset(leaf, fi); | ||
7059 | exts[nr].num_bytes = btrfs_file_extent_num_bytes(leaf, fi); | ||
7060 | exts[nr].ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi); | ||
7061 | exts[nr].compression = btrfs_file_extent_compression(leaf, fi); | ||
7062 | exts[nr].encryption = btrfs_file_extent_encryption(leaf, fi); | ||
7063 | exts[nr].other_encoding = btrfs_file_extent_other_encoding(leaf, | ||
7064 | fi); | ||
7065 | BUG_ON(exts[nr].offset > 0); | ||
7066 | BUG_ON(exts[nr].compression || exts[nr].encryption); | ||
7067 | BUG_ON(exts[nr].num_bytes != exts[nr].disk_num_bytes); | ||
7068 | |||
7069 | cur_pos += exts[nr].num_bytes; | ||
7070 | nr++; | ||
7071 | |||
7072 | if (cur_pos + offset >= last_byte) | ||
7073 | break; | ||
7074 | |||
7075 | if (no_fragment) { | ||
7076 | ret = 1; | ||
7077 | goto out; | ||
7078 | } | ||
7079 | path->slots[0]++; | ||
7080 | } | ||
7081 | |||
7082 | BUG_ON(cur_pos + offset > last_byte); | ||
7083 | if (cur_pos + offset < last_byte) { | ||
7084 | ret = -ENOENT; | ||
7085 | goto out; | ||
7086 | } | ||
7087 | ret = 0; | ||
7088 | out: | ||
7089 | btrfs_free_path(path); | ||
7090 | if (ret) { | ||
7091 | if (exts != *extents) | ||
7092 | kfree(exts); | ||
7093 | } else { | ||
7094 | *extents = exts; | ||
7095 | *nr_extents = nr; | ||
7096 | } | ||
7097 | return ret; | ||
7098 | } | ||
7099 | |||
7100 | static noinline int replace_one_extent(struct btrfs_trans_handle *trans, | ||
7101 | struct btrfs_root *root, | ||
7102 | struct btrfs_path *path, | ||
7103 | struct btrfs_key *extent_key, | ||
7104 | struct btrfs_key *leaf_key, | ||
7105 | struct btrfs_ref_path *ref_path, | ||
7106 | struct disk_extent *new_extents, | ||
7107 | int nr_extents) | ||
7108 | { | ||
7109 | struct extent_buffer *leaf; | ||
7110 | struct btrfs_file_extent_item *fi; | ||
7111 | struct inode *inode = NULL; | ||
7112 | struct btrfs_key key; | ||
7113 | u64 lock_start = 0; | ||
7114 | u64 lock_end = 0; | ||
7115 | u64 num_bytes; | ||
7116 | u64 ext_offset; | ||
7117 | u64 search_end = (u64)-1; | ||
7118 | u32 nritems; | ||
7119 | int nr_scaned = 0; | ||
7120 | int extent_locked = 0; | ||
7121 | int extent_type; | ||
7122 | int ret; | ||
7123 | |||
7124 | memcpy(&key, leaf_key, sizeof(key)); | ||
7125 | if (ref_path->owner_objectid != BTRFS_MULTIPLE_OBJECTIDS) { | ||
7126 | if (key.objectid < ref_path->owner_objectid || | ||
7127 | (key.objectid == ref_path->owner_objectid && | ||
7128 | key.type < BTRFS_EXTENT_DATA_KEY)) { | ||
7129 | key.objectid = ref_path->owner_objectid; | ||
7130 | key.type = BTRFS_EXTENT_DATA_KEY; | ||
7131 | key.offset = 0; | ||
7132 | } | ||
7133 | } | ||
7134 | |||
7135 | while (1) { | ||
7136 | ret = btrfs_search_slot(trans, root, &key, path, 0, 1); | ||
7137 | if (ret < 0) | ||
7138 | goto out; | ||
7139 | |||
7140 | leaf = path->nodes[0]; | ||
7141 | nritems = btrfs_header_nritems(leaf); | ||
7142 | next: | ||
7143 | if (extent_locked && ret > 0) { | ||
7144 | /* | ||
7145 | * the file extent item was modified by someone | ||
7146 | * before the extent got locked. | ||
7147 | */ | ||
7148 | unlock_extent(&BTRFS_I(inode)->io_tree, lock_start, | ||
7149 | lock_end, GFP_NOFS); | ||
7150 | extent_locked = 0; | ||
7151 | } | ||
7152 | |||
7153 | if (path->slots[0] >= nritems) { | ||
7154 | if (++nr_scaned > 2) | ||
7155 | break; | ||
7156 | |||
7157 | BUG_ON(extent_locked); | ||
7158 | ret = btrfs_next_leaf(root, path); | ||
7159 | if (ret < 0) | ||
7160 | goto out; | ||
7161 | if (ret > 0) | ||
7162 | break; | ||
7163 | leaf = path->nodes[0]; | ||
7164 | nritems = btrfs_header_nritems(leaf); | ||
7165 | } | ||
7166 | |||
7167 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); | ||
7168 | |||
7169 | if (ref_path->owner_objectid != BTRFS_MULTIPLE_OBJECTIDS) { | ||
7170 | if ((key.objectid > ref_path->owner_objectid) || | ||
7171 | (key.objectid == ref_path->owner_objectid && | ||
7172 | key.type > BTRFS_EXTENT_DATA_KEY) || | ||
7173 | key.offset >= search_end) | ||
7174 | break; | ||
7175 | } | ||
7176 | |||
7177 | if (inode && key.objectid != btrfs_ino(inode)) { | ||
7178 | BUG_ON(extent_locked); | ||
7179 | btrfs_release_path(root, path); | ||
7180 | mutex_unlock(&inode->i_mutex); | ||
7181 | iput(inode); | ||
7182 | inode = NULL; | ||
7183 | continue; | ||
7184 | } | ||
7185 | |||
7186 | if (key.type != BTRFS_EXTENT_DATA_KEY) { | ||
7187 | path->slots[0]++; | ||
7188 | ret = 1; | ||
7189 | goto next; | ||
7190 | } | ||
7191 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
7192 | struct btrfs_file_extent_item); | ||
7193 | extent_type = btrfs_file_extent_type(leaf, fi); | ||
7194 | if ((extent_type != BTRFS_FILE_EXTENT_REG && | ||
7195 | extent_type != BTRFS_FILE_EXTENT_PREALLOC) || | ||
7196 | (btrfs_file_extent_disk_bytenr(leaf, fi) != | ||
7197 | extent_key->objectid)) { | ||
7198 | path->slots[0]++; | ||
7199 | ret = 1; | ||
7200 | goto next; | ||
7201 | } | ||
7202 | |||
7203 | num_bytes = btrfs_file_extent_num_bytes(leaf, fi); | ||
7204 | ext_offset = btrfs_file_extent_offset(leaf, fi); | ||
7205 | |||
7206 | if (search_end == (u64)-1) { | ||
7207 | search_end = key.offset - ext_offset + | ||
7208 | btrfs_file_extent_ram_bytes(leaf, fi); | ||
7209 | } | ||
7210 | |||
7211 | if (!extent_locked) { | ||
7212 | lock_start = key.offset; | ||
7213 | lock_end = lock_start + num_bytes - 1; | ||
7214 | } else { | ||
7215 | if (lock_start > key.offset || | ||
7216 | lock_end + 1 < key.offset + num_bytes) { | ||
7217 | unlock_extent(&BTRFS_I(inode)->io_tree, | ||
7218 | lock_start, lock_end, GFP_NOFS); | ||
7219 | extent_locked = 0; | ||
7220 | } | ||
7221 | } | ||
7222 | |||
7223 | if (!inode) { | ||
7224 | btrfs_release_path(root, path); | ||
7225 | |||
7226 | inode = btrfs_iget_locked(root->fs_info->sb, | ||
7227 | key.objectid, root); | ||
7228 | if (inode->i_state & I_NEW) { | ||
7229 | BTRFS_I(inode)->root = root; | ||
7230 | BTRFS_I(inode)->location.objectid = | ||
7231 | key.objectid; | ||
7232 | BTRFS_I(inode)->location.type = | ||
7233 | BTRFS_INODE_ITEM_KEY; | ||
7234 | BTRFS_I(inode)->location.offset = 0; | ||
7235 | btrfs_read_locked_inode(inode); | ||
7236 | unlock_new_inode(inode); | ||
7237 | } | ||
7238 | /* | ||
7239 | * some code call btrfs_commit_transaction while | ||
7240 | * holding the i_mutex, so we can't use mutex_lock | ||
7241 | * here. | ||
7242 | */ | ||
7243 | if (is_bad_inode(inode) || | ||
7244 | !mutex_trylock(&inode->i_mutex)) { | ||
7245 | iput(inode); | ||
7246 | inode = NULL; | ||
7247 | key.offset = (u64)-1; | ||
7248 | goto skip; | ||
7249 | } | ||
7250 | } | ||
7251 | |||
7252 | if (!extent_locked) { | ||
7253 | struct btrfs_ordered_extent *ordered; | ||
7254 | |||
7255 | btrfs_release_path(root, path); | ||
7256 | |||
7257 | lock_extent(&BTRFS_I(inode)->io_tree, lock_start, | ||
7258 | lock_end, GFP_NOFS); | ||
7259 | ordered = btrfs_lookup_first_ordered_extent(inode, | ||
7260 | lock_end); | ||
7261 | if (ordered && | ||
7262 | ordered->file_offset <= lock_end && | ||
7263 | ordered->file_offset + ordered->len > lock_start) { | ||
7264 | unlock_extent(&BTRFS_I(inode)->io_tree, | ||
7265 | lock_start, lock_end, GFP_NOFS); | ||
7266 | btrfs_start_ordered_extent(inode, ordered, 1); | ||
7267 | btrfs_put_ordered_extent(ordered); | ||
7268 | key.offset += num_bytes; | ||
7269 | goto skip; | ||
7270 | } | ||
7271 | if (ordered) | ||
7272 | btrfs_put_ordered_extent(ordered); | ||
7273 | |||
7274 | extent_locked = 1; | ||
7275 | continue; | ||
7276 | } | ||
7277 | |||
7278 | if (nr_extents == 1) { | ||
7279 | /* update extent pointer in place */ | ||
7280 | btrfs_set_file_extent_disk_bytenr(leaf, fi, | ||
7281 | new_extents[0].disk_bytenr); | ||
7282 | btrfs_set_file_extent_disk_num_bytes(leaf, fi, | ||
7283 | new_extents[0].disk_num_bytes); | ||
7284 | btrfs_mark_buffer_dirty(leaf); | ||
7285 | |||
7286 | btrfs_drop_extent_cache(inode, key.offset, | ||
7287 | key.offset + num_bytes - 1, 0); | ||
7288 | |||
7289 | ret = btrfs_inc_extent_ref(trans, root, | ||
7290 | new_extents[0].disk_bytenr, | ||
7291 | new_extents[0].disk_num_bytes, | ||
7292 | leaf->start, | ||
7293 | root->root_key.objectid, | ||
7294 | trans->transid, | ||
7295 | key.objectid); | ||
7296 | BUG_ON(ret); | ||
7297 | |||
7298 | ret = btrfs_free_extent(trans, root, | ||
7299 | extent_key->objectid, | ||
7300 | extent_key->offset, | ||
7301 | leaf->start, | ||
7302 | btrfs_header_owner(leaf), | ||
7303 | btrfs_header_generation(leaf), | ||
7304 | key.objectid, 0); | ||
7305 | BUG_ON(ret); | ||
7306 | |||
7307 | btrfs_release_path(root, path); | ||
7308 | key.offset += num_bytes; | ||
7309 | } else { | ||
7310 | BUG_ON(1); | ||
7311 | #if 0 | ||
7312 | u64 alloc_hint; | ||
7313 | u64 extent_len; | ||
7314 | int i; | ||
7315 | /* | ||
7316 | * drop old extent pointer at first, then insert the | ||
7317 | * new pointers one bye one | ||
7318 | */ | ||
7319 | btrfs_release_path(root, path); | ||
7320 | ret = btrfs_drop_extents(trans, root, inode, key.offset, | ||
7321 | key.offset + num_bytes, | ||
7322 | key.offset, &alloc_hint); | ||
7323 | BUG_ON(ret); | ||
7324 | |||
7325 | for (i = 0; i < nr_extents; i++) { | ||
7326 | if (ext_offset >= new_extents[i].num_bytes) { | ||
7327 | ext_offset -= new_extents[i].num_bytes; | ||
7328 | continue; | ||
7329 | } | ||
7330 | extent_len = min(new_extents[i].num_bytes - | ||
7331 | ext_offset, num_bytes); | ||
7332 | |||
7333 | ret = btrfs_insert_empty_item(trans, root, | ||
7334 | path, &key, | ||
7335 | sizeof(*fi)); | ||
7336 | BUG_ON(ret); | ||
7337 | |||
7338 | leaf = path->nodes[0]; | ||
7339 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
7340 | struct btrfs_file_extent_item); | ||
7341 | btrfs_set_file_extent_generation(leaf, fi, | ||
7342 | trans->transid); | ||
7343 | btrfs_set_file_extent_type(leaf, fi, | ||
7344 | BTRFS_FILE_EXTENT_REG); | ||
7345 | btrfs_set_file_extent_disk_bytenr(leaf, fi, | ||
7346 | new_extents[i].disk_bytenr); | ||
7347 | btrfs_set_file_extent_disk_num_bytes(leaf, fi, | ||
7348 | new_extents[i].disk_num_bytes); | ||
7349 | btrfs_set_file_extent_ram_bytes(leaf, fi, | ||
7350 | new_extents[i].ram_bytes); | ||
7351 | |||
7352 | btrfs_set_file_extent_compression(leaf, fi, | ||
7353 | new_extents[i].compression); | ||
7354 | btrfs_set_file_extent_encryption(leaf, fi, | ||
7355 | new_extents[i].encryption); | ||
7356 | btrfs_set_file_extent_other_encoding(leaf, fi, | ||
7357 | new_extents[i].other_encoding); | ||
7358 | |||
7359 | btrfs_set_file_extent_num_bytes(leaf, fi, | ||
7360 | extent_len); | ||
7361 | ext_offset += new_extents[i].offset; | ||
7362 | btrfs_set_file_extent_offset(leaf, fi, | ||
7363 | ext_offset); | ||
7364 | btrfs_mark_buffer_dirty(leaf); | ||
7365 | |||
7366 | btrfs_drop_extent_cache(inode, key.offset, | ||
7367 | key.offset + extent_len - 1, 0); | ||
7368 | |||
7369 | ret = btrfs_inc_extent_ref(trans, root, | ||
7370 | new_extents[i].disk_bytenr, | ||
7371 | new_extents[i].disk_num_bytes, | ||
7372 | leaf->start, | ||
7373 | root->root_key.objectid, | ||
7374 | trans->transid, key.objectid); | ||
7375 | BUG_ON(ret); | ||
7376 | btrfs_release_path(root, path); | ||
7377 | |||
7378 | inode_add_bytes(inode, extent_len); | ||
7379 | |||
7380 | ext_offset = 0; | ||
7381 | num_bytes -= extent_len; | ||
7382 | key.offset += extent_len; | ||
7383 | |||
7384 | if (num_bytes == 0) | ||
7385 | break; | ||
7386 | } | ||
7387 | BUG_ON(i >= nr_extents); | ||
7388 | #endif | ||
7389 | } | ||
7390 | |||
7391 | if (extent_locked) { | ||
7392 | unlock_extent(&BTRFS_I(inode)->io_tree, lock_start, | ||
7393 | lock_end, GFP_NOFS); | ||
7394 | extent_locked = 0; | ||
7395 | } | ||
7396 | skip: | ||
7397 | if (ref_path->owner_objectid != BTRFS_MULTIPLE_OBJECTIDS && | ||
7398 | key.offset >= search_end) | ||
7399 | break; | ||
7400 | |||
7401 | cond_resched(); | ||
7402 | } | ||
7403 | ret = 0; | ||
7404 | out: | ||
7405 | btrfs_release_path(root, path); | ||
7406 | if (inode) { | ||
7407 | mutex_unlock(&inode->i_mutex); | ||
7408 | if (extent_locked) { | ||
7409 | unlock_extent(&BTRFS_I(inode)->io_tree, lock_start, | ||
7410 | lock_end, GFP_NOFS); | ||
7411 | } | ||
7412 | iput(inode); | ||
7413 | } | ||
7414 | return ret; | ||
7415 | } | ||
7416 | |||
7417 | int btrfs_reloc_tree_cache_ref(struct btrfs_trans_handle *trans, | ||
7418 | struct btrfs_root *root, | ||
7419 | struct extent_buffer *buf, u64 orig_start) | ||
7420 | { | ||
7421 | int level; | ||
7422 | int ret; | ||
7423 | |||
7424 | BUG_ON(btrfs_header_generation(buf) != trans->transid); | ||
7425 | BUG_ON(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID); | ||
7426 | |||
7427 | level = btrfs_header_level(buf); | ||
7428 | if (level == 0) { | ||
7429 | struct btrfs_leaf_ref *ref; | ||
7430 | struct btrfs_leaf_ref *orig_ref; | ||
7431 | |||
7432 | orig_ref = btrfs_lookup_leaf_ref(root, orig_start); | ||
7433 | if (!orig_ref) | ||
7434 | return -ENOENT; | ||
7435 | |||
7436 | ref = btrfs_alloc_leaf_ref(root, orig_ref->nritems); | ||
7437 | if (!ref) { | ||
7438 | btrfs_free_leaf_ref(root, orig_ref); | ||
7439 | return -ENOMEM; | ||
7440 | } | ||
7441 | |||
7442 | ref->nritems = orig_ref->nritems; | ||
7443 | memcpy(ref->extents, orig_ref->extents, | ||
7444 | sizeof(ref->extents[0]) * ref->nritems); | ||
7445 | |||
7446 | btrfs_free_leaf_ref(root, orig_ref); | ||
7447 | |||
7448 | ref->root_gen = trans->transid; | ||
7449 | ref->bytenr = buf->start; | ||
7450 | ref->owner = btrfs_header_owner(buf); | ||
7451 | ref->generation = btrfs_header_generation(buf); | ||
7452 | |||
7453 | ret = btrfs_add_leaf_ref(root, ref, 0); | ||
7454 | WARN_ON(ret); | ||
7455 | btrfs_free_leaf_ref(root, ref); | ||
7456 | } | ||
7457 | return 0; | ||
7458 | } | ||
7459 | |||
7460 | static noinline int invalidate_extent_cache(struct btrfs_root *root, | ||
7461 | struct extent_buffer *leaf, | ||
7462 | struct btrfs_block_group_cache *group, | ||
7463 | struct btrfs_root *target_root) | ||
7464 | { | ||
7465 | struct btrfs_key key; | ||
7466 | struct inode *inode = NULL; | ||
7467 | struct btrfs_file_extent_item *fi; | ||
7468 | struct extent_state *cached_state = NULL; | ||
7469 | u64 num_bytes; | ||
7470 | u64 skip_objectid = 0; | ||
7471 | u32 nritems; | ||
7472 | u32 i; | ||
7473 | |||
7474 | nritems = btrfs_header_nritems(leaf); | ||
7475 | for (i = 0; i < nritems; i++) { | ||
7476 | btrfs_item_key_to_cpu(leaf, &key, i); | ||
7477 | if (key.objectid == skip_objectid || | ||
7478 | key.type != BTRFS_EXTENT_DATA_KEY) | ||
7479 | continue; | ||
7480 | fi = btrfs_item_ptr(leaf, i, struct btrfs_file_extent_item); | ||
7481 | if (btrfs_file_extent_type(leaf, fi) == | ||
7482 | BTRFS_FILE_EXTENT_INLINE) | ||
7483 | continue; | ||
7484 | if (btrfs_file_extent_disk_bytenr(leaf, fi) == 0) | ||
7485 | continue; | ||
7486 | if (!inode || btrfs_ino(inode) != key.objectid) { | ||
7487 | iput(inode); | ||
7488 | inode = btrfs_ilookup(target_root->fs_info->sb, | ||
7489 | key.objectid, target_root, 1); | ||
7490 | } | ||
7491 | if (!inode) { | ||
7492 | skip_objectid = key.objectid; | ||
7493 | continue; | ||
7494 | } | ||
7495 | num_bytes = btrfs_file_extent_num_bytes(leaf, fi); | ||
7496 | |||
7497 | lock_extent_bits(&BTRFS_I(inode)->io_tree, key.offset, | ||
7498 | key.offset + num_bytes - 1, 0, &cached_state, | ||
7499 | GFP_NOFS); | ||
7500 | btrfs_drop_extent_cache(inode, key.offset, | ||
7501 | key.offset + num_bytes - 1, 1); | ||
7502 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, key.offset, | ||
7503 | key.offset + num_bytes - 1, &cached_state, | ||
7504 | GFP_NOFS); | ||
7505 | cond_resched(); | ||
7506 | } | ||
7507 | iput(inode); | ||
7508 | return 0; | ||
7509 | } | ||
7510 | |||
7511 | static noinline int replace_extents_in_leaf(struct btrfs_trans_handle *trans, | ||
7512 | struct btrfs_root *root, | ||
7513 | struct extent_buffer *leaf, | ||
7514 | struct btrfs_block_group_cache *group, | ||
7515 | struct inode *reloc_inode) | ||
7516 | { | ||
7517 | struct btrfs_key key; | ||
7518 | struct btrfs_key extent_key; | ||
7519 | struct btrfs_file_extent_item *fi; | ||
7520 | struct btrfs_leaf_ref *ref; | ||
7521 | struct disk_extent *new_extent; | ||
7522 | u64 bytenr; | ||
7523 | u64 num_bytes; | ||
7524 | u32 nritems; | ||
7525 | u32 i; | ||
7526 | int ext_index; | ||
7527 | int nr_extent; | ||
7528 | int ret; | ||
7529 | |||
7530 | new_extent = kmalloc(sizeof(*new_extent), GFP_NOFS); | ||
7531 | if (!new_extent) | ||
7532 | return -ENOMEM; | ||
7533 | |||
7534 | ref = btrfs_lookup_leaf_ref(root, leaf->start); | ||
7535 | BUG_ON(!ref); | ||
7536 | |||
7537 | ext_index = -1; | ||
7538 | nritems = btrfs_header_nritems(leaf); | ||
7539 | for (i = 0; i < nritems; i++) { | ||
7540 | btrfs_item_key_to_cpu(leaf, &key, i); | ||
7541 | if (btrfs_key_type(&key) != BTRFS_EXTENT_DATA_KEY) | ||
7542 | continue; | ||
7543 | fi = btrfs_item_ptr(leaf, i, struct btrfs_file_extent_item); | ||
7544 | if (btrfs_file_extent_type(leaf, fi) == | ||
7545 | BTRFS_FILE_EXTENT_INLINE) | ||
7546 | continue; | ||
7547 | bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); | ||
7548 | num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi); | ||
7549 | if (bytenr == 0) | ||
7550 | continue; | ||
7551 | |||
7552 | ext_index++; | ||
7553 | if (bytenr >= group->key.objectid + group->key.offset || | ||
7554 | bytenr + num_bytes <= group->key.objectid) | ||
7555 | continue; | ||
7556 | |||
7557 | extent_key.objectid = bytenr; | ||
7558 | extent_key.offset = num_bytes; | ||
7559 | extent_key.type = BTRFS_EXTENT_ITEM_KEY; | ||
7560 | nr_extent = 1; | ||
7561 | ret = get_new_locations(reloc_inode, &extent_key, | ||
7562 | group->key.objectid, 1, | ||
7563 | &new_extent, &nr_extent); | ||
7564 | if (ret > 0) | ||
7565 | continue; | ||
7566 | BUG_ON(ret < 0); | ||
7567 | |||
7568 | BUG_ON(ref->extents[ext_index].bytenr != bytenr); | ||
7569 | BUG_ON(ref->extents[ext_index].num_bytes != num_bytes); | ||
7570 | ref->extents[ext_index].bytenr = new_extent->disk_bytenr; | ||
7571 | ref->extents[ext_index].num_bytes = new_extent->disk_num_bytes; | ||
7572 | |||
7573 | btrfs_set_file_extent_disk_bytenr(leaf, fi, | ||
7574 | new_extent->disk_bytenr); | ||
7575 | btrfs_set_file_extent_disk_num_bytes(leaf, fi, | ||
7576 | new_extent->disk_num_bytes); | ||
7577 | btrfs_mark_buffer_dirty(leaf); | ||
7578 | |||
7579 | ret = btrfs_inc_extent_ref(trans, root, | ||
7580 | new_extent->disk_bytenr, | ||
7581 | new_extent->disk_num_bytes, | ||
7582 | leaf->start, | ||
7583 | root->root_key.objectid, | ||
7584 | trans->transid, key.objectid); | ||
7585 | BUG_ON(ret); | ||
7586 | |||
7587 | ret = btrfs_free_extent(trans, root, | ||
7588 | bytenr, num_bytes, leaf->start, | ||
7589 | btrfs_header_owner(leaf), | ||
7590 | btrfs_header_generation(leaf), | ||
7591 | key.objectid, 0); | ||
7592 | BUG_ON(ret); | ||
7593 | cond_resched(); | ||
7594 | } | ||
7595 | kfree(new_extent); | ||
7596 | BUG_ON(ext_index + 1 != ref->nritems); | ||
7597 | btrfs_free_leaf_ref(root, ref); | ||
7598 | return 0; | ||
7599 | } | ||
7600 | |||
7601 | int btrfs_free_reloc_root(struct btrfs_trans_handle *trans, | ||
7602 | struct btrfs_root *root) | ||
7603 | { | ||
7604 | struct btrfs_root *reloc_root; | ||
7605 | int ret; | ||
7606 | |||
7607 | if (root->reloc_root) { | ||
7608 | reloc_root = root->reloc_root; | ||
7609 | root->reloc_root = NULL; | ||
7610 | list_add(&reloc_root->dead_list, | ||
7611 | &root->fs_info->dead_reloc_roots); | ||
7612 | |||
7613 | btrfs_set_root_bytenr(&reloc_root->root_item, | ||
7614 | reloc_root->node->start); | ||
7615 | btrfs_set_root_level(&root->root_item, | ||
7616 | btrfs_header_level(reloc_root->node)); | ||
7617 | memset(&reloc_root->root_item.drop_progress, 0, | ||
7618 | sizeof(struct btrfs_disk_key)); | ||
7619 | reloc_root->root_item.drop_level = 0; | ||
7620 | |||
7621 | ret = btrfs_update_root(trans, root->fs_info->tree_root, | ||
7622 | &reloc_root->root_key, | ||
7623 | &reloc_root->root_item); | ||
7624 | BUG_ON(ret); | ||
7625 | } | ||
7626 | return 0; | ||
7627 | } | ||
7628 | |||
7629 | int btrfs_drop_dead_reloc_roots(struct btrfs_root *root) | ||
7630 | { | ||
7631 | struct btrfs_trans_handle *trans; | ||
7632 | struct btrfs_root *reloc_root; | ||
7633 | struct btrfs_root *prev_root = NULL; | ||
7634 | struct list_head dead_roots; | ||
7635 | int ret; | ||
7636 | unsigned long nr; | ||
7637 | |||
7638 | INIT_LIST_HEAD(&dead_roots); | ||
7639 | list_splice_init(&root->fs_info->dead_reloc_roots, &dead_roots); | ||
7640 | |||
7641 | while (!list_empty(&dead_roots)) { | ||
7642 | reloc_root = list_entry(dead_roots.prev, | ||
7643 | struct btrfs_root, dead_list); | ||
7644 | list_del_init(&reloc_root->dead_list); | ||
7645 | |||
7646 | BUG_ON(reloc_root->commit_root != NULL); | ||
7647 | while (1) { | ||
7648 | trans = btrfs_join_transaction(root, 1); | ||
7649 | BUG_ON(IS_ERR(trans)); | ||
7650 | |||
7651 | mutex_lock(&root->fs_info->drop_mutex); | ||
7652 | ret = btrfs_drop_snapshot(trans, reloc_root); | ||
7653 | if (ret != -EAGAIN) | ||
7654 | break; | ||
7655 | mutex_unlock(&root->fs_info->drop_mutex); | ||
7656 | |||
7657 | nr = trans->blocks_used; | ||
7658 | ret = btrfs_end_transaction(trans, root); | ||
7659 | BUG_ON(ret); | ||
7660 | btrfs_btree_balance_dirty(root, nr); | ||
7661 | } | ||
7662 | |||
7663 | free_extent_buffer(reloc_root->node); | ||
7664 | |||
7665 | ret = btrfs_del_root(trans, root->fs_info->tree_root, | ||
7666 | &reloc_root->root_key); | ||
7667 | BUG_ON(ret); | ||
7668 | mutex_unlock(&root->fs_info->drop_mutex); | ||
7669 | |||
7670 | nr = trans->blocks_used; | ||
7671 | ret = btrfs_end_transaction(trans, root); | ||
7672 | BUG_ON(ret); | ||
7673 | btrfs_btree_balance_dirty(root, nr); | ||
7674 | |||
7675 | kfree(prev_root); | ||
7676 | prev_root = reloc_root; | ||
7677 | } | ||
7678 | if (prev_root) { | ||
7679 | btrfs_remove_leaf_refs(prev_root, (u64)-1, 0); | ||
7680 | kfree(prev_root); | ||
7681 | } | ||
7682 | return 0; | ||
7683 | } | ||
7684 | |||
7685 | int btrfs_add_dead_reloc_root(struct btrfs_root *root) | ||
7686 | { | ||
7687 | list_add(&root->dead_list, &root->fs_info->dead_reloc_roots); | ||
7688 | return 0; | ||
7689 | } | ||
7690 | |||
7691 | int btrfs_cleanup_reloc_trees(struct btrfs_root *root) | ||
7692 | { | ||
7693 | struct btrfs_root *reloc_root; | ||
7694 | struct btrfs_trans_handle *trans; | ||
7695 | struct btrfs_key location; | ||
7696 | int found; | ||
7697 | int ret; | ||
7698 | |||
7699 | mutex_lock(&root->fs_info->tree_reloc_mutex); | ||
7700 | ret = btrfs_find_dead_roots(root, BTRFS_TREE_RELOC_OBJECTID, NULL); | ||
7701 | BUG_ON(ret); | ||
7702 | found = !list_empty(&root->fs_info->dead_reloc_roots); | ||
7703 | mutex_unlock(&root->fs_info->tree_reloc_mutex); | ||
7704 | |||
7705 | if (found) { | ||
7706 | trans = btrfs_start_transaction(root, 1); | ||
7707 | BUG_ON(IS_ERR(trans)); | ||
7708 | ret = btrfs_commit_transaction(trans, root); | ||
7709 | BUG_ON(ret); | ||
7710 | } | ||
7711 | |||
7712 | location.objectid = BTRFS_DATA_RELOC_TREE_OBJECTID; | ||
7713 | location.offset = (u64)-1; | ||
7714 | location.type = BTRFS_ROOT_ITEM_KEY; | ||
7715 | |||
7716 | reloc_root = btrfs_read_fs_root_no_name(root->fs_info, &location); | ||
7717 | BUG_ON(!reloc_root); | ||
7718 | ret = btrfs_orphan_cleanup(reloc_root); | ||
7719 | BUG_ON(ret); | ||
7720 | return 0; | ||
7721 | } | ||
7722 | |||
7723 | static noinline int init_reloc_tree(struct btrfs_trans_handle *trans, | ||
7724 | struct btrfs_root *root) | ||
7725 | { | ||
7726 | struct btrfs_root *reloc_root; | ||
7727 | struct extent_buffer *eb; | ||
7728 | struct btrfs_root_item *root_item; | ||
7729 | struct btrfs_key root_key; | ||
7730 | int ret; | ||
7731 | |||
7732 | BUG_ON(!root->ref_cows); | ||
7733 | if (root->reloc_root) | ||
7734 | return 0; | ||
7735 | |||
7736 | root_item = kmalloc(sizeof(*root_item), GFP_NOFS); | ||
7737 | if (!root_item) | ||
7738 | return -ENOMEM; | ||
7739 | |||
7740 | ret = btrfs_copy_root(trans, root, root->commit_root, | ||
7741 | &eb, BTRFS_TREE_RELOC_OBJECTID); | ||
7742 | BUG_ON(ret); | ||
7743 | |||
7744 | root_key.objectid = BTRFS_TREE_RELOC_OBJECTID; | ||
7745 | root_key.offset = root->root_key.objectid; | ||
7746 | root_key.type = BTRFS_ROOT_ITEM_KEY; | ||
7747 | |||
7748 | memcpy(root_item, &root->root_item, sizeof(root_item)); | ||
7749 | btrfs_set_root_refs(root_item, 0); | ||
7750 | btrfs_set_root_bytenr(root_item, eb->start); | ||
7751 | btrfs_set_root_level(root_item, btrfs_header_level(eb)); | ||
7752 | btrfs_set_root_generation(root_item, trans->transid); | ||
7753 | |||
7754 | btrfs_tree_unlock(eb); | ||
7755 | free_extent_buffer(eb); | ||
7756 | |||
7757 | ret = btrfs_insert_root(trans, root->fs_info->tree_root, | ||
7758 | &root_key, root_item); | ||
7759 | BUG_ON(ret); | ||
7760 | kfree(root_item); | ||
7761 | |||
7762 | reloc_root = btrfs_read_fs_root_no_radix(root->fs_info->tree_root, | ||
7763 | &root_key); | ||
7764 | BUG_ON(IS_ERR(reloc_root)); | ||
7765 | reloc_root->last_trans = trans->transid; | ||
7766 | reloc_root->commit_root = NULL; | ||
7767 | reloc_root->ref_tree = &root->fs_info->reloc_ref_tree; | ||
7768 | |||
7769 | root->reloc_root = reloc_root; | ||
7770 | return 0; | ||
7771 | } | ||
7772 | |||
7773 | /* | ||
7774 | * Core function of space balance. | ||
7775 | * | ||
7776 | * The idea is using reloc trees to relocate tree blocks in reference | ||
7777 | * counted roots. There is one reloc tree for each subvol, and all | ||
7778 | * reloc trees share same root key objectid. Reloc trees are snapshots | ||
7779 | * of the latest committed roots of subvols (root->commit_root). | ||
7780 | * | ||
7781 | * To relocate a tree block referenced by a subvol, there are two steps. | ||
7782 | * COW the block through subvol's reloc tree, then update block pointer | ||
7783 | * in the subvol to point to the new block. Since all reloc trees share | ||
7784 | * same root key objectid, doing special handing for tree blocks owned | ||
7785 | * by them is easy. Once a tree block has been COWed in one reloc tree, | ||
7786 | * we can use the resulting new block directly when the same block is | ||
7787 | * required to COW again through other reloc trees. By this way, relocated | ||
7788 | * tree blocks are shared between reloc trees, so they are also shared | ||
7789 | * between subvols. | ||
7790 | */ | ||
7791 | static noinline int relocate_one_path(struct btrfs_trans_handle *trans, | ||
7792 | struct btrfs_root *root, | ||
7793 | struct btrfs_path *path, | ||
7794 | struct btrfs_key *first_key, | ||
7795 | struct btrfs_ref_path *ref_path, | ||
7796 | struct btrfs_block_group_cache *group, | ||
7797 | struct inode *reloc_inode) | ||
7798 | { | ||
7799 | struct btrfs_root *reloc_root; | ||
7800 | struct extent_buffer *eb = NULL; | ||
7801 | struct btrfs_key *keys; | ||
7802 | u64 *nodes; | ||
7803 | int level; | ||
7804 | int shared_level; | ||
7805 | int lowest_level = 0; | ||
7806 | int ret; | ||
7807 | |||
7808 | if (ref_path->owner_objectid < BTRFS_FIRST_FREE_OBJECTID) | ||
7809 | lowest_level = ref_path->owner_objectid; | ||
7810 | |||
7811 | if (!root->ref_cows) { | ||
7812 | path->lowest_level = lowest_level; | ||
7813 | ret = btrfs_search_slot(trans, root, first_key, path, 0, 1); | ||
7814 | BUG_ON(ret < 0); | ||
7815 | path->lowest_level = 0; | ||
7816 | btrfs_release_path(root, path); | ||
7817 | return 0; | ||
7818 | } | ||
7819 | |||
7820 | mutex_lock(&root->fs_info->tree_reloc_mutex); | ||
7821 | ret = init_reloc_tree(trans, root); | ||
7822 | BUG_ON(ret); | ||
7823 | reloc_root = root->reloc_root; | ||
7824 | |||
7825 | shared_level = ref_path->shared_level; | ||
7826 | ref_path->shared_level = BTRFS_MAX_LEVEL - 1; | ||
7827 | |||
7828 | keys = ref_path->node_keys; | ||
7829 | nodes = ref_path->new_nodes; | ||
7830 | memset(&keys[shared_level + 1], 0, | ||
7831 | sizeof(*keys) * (BTRFS_MAX_LEVEL - shared_level - 1)); | ||
7832 | memset(&nodes[shared_level + 1], 0, | ||
7833 | sizeof(*nodes) * (BTRFS_MAX_LEVEL - shared_level - 1)); | ||
7834 | |||
7835 | if (nodes[lowest_level] == 0) { | ||
7836 | path->lowest_level = lowest_level; | ||
7837 | ret = btrfs_search_slot(trans, reloc_root, first_key, path, | ||
7838 | 0, 1); | ||
7839 | BUG_ON(ret); | ||
7840 | for (level = lowest_level; level < BTRFS_MAX_LEVEL; level++) { | ||
7841 | eb = path->nodes[level]; | ||
7842 | if (!eb || eb == reloc_root->node) | ||
7843 | break; | ||
7844 | nodes[level] = eb->start; | ||
7845 | if (level == 0) | ||
7846 | btrfs_item_key_to_cpu(eb, &keys[level], 0); | ||
7847 | else | ||
7848 | btrfs_node_key_to_cpu(eb, &keys[level], 0); | ||
7849 | } | ||
7850 | if (nodes[0] && | ||
7851 | ref_path->owner_objectid >= BTRFS_FIRST_FREE_OBJECTID) { | ||
7852 | eb = path->nodes[0]; | ||
7853 | ret = replace_extents_in_leaf(trans, reloc_root, eb, | ||
7854 | group, reloc_inode); | ||
7855 | BUG_ON(ret); | ||
7856 | } | ||
7857 | btrfs_release_path(reloc_root, path); | ||
7858 | } else { | ||
7859 | ret = btrfs_merge_path(trans, reloc_root, keys, nodes, | ||
7860 | lowest_level); | ||
7861 | BUG_ON(ret); | ||
7862 | } | ||
7863 | |||
7864 | /* | ||
7865 | * replace tree blocks in the fs tree with tree blocks in | ||
7866 | * the reloc tree. | ||
7867 | */ | ||
7868 | ret = btrfs_merge_path(trans, root, keys, nodes, lowest_level); | ||
7869 | BUG_ON(ret < 0); | ||
7870 | |||
7871 | if (ref_path->owner_objectid >= BTRFS_FIRST_FREE_OBJECTID) { | ||
7872 | ret = btrfs_search_slot(trans, reloc_root, first_key, path, | ||
7873 | 0, 0); | ||
7874 | BUG_ON(ret); | ||
7875 | extent_buffer_get(path->nodes[0]); | ||
7876 | eb = path->nodes[0]; | ||
7877 | btrfs_release_path(reloc_root, path); | ||
7878 | ret = invalidate_extent_cache(reloc_root, eb, group, root); | ||
7879 | BUG_ON(ret); | ||
7880 | free_extent_buffer(eb); | ||
7881 | } | ||
7882 | |||
7883 | mutex_unlock(&root->fs_info->tree_reloc_mutex); | ||
7884 | path->lowest_level = 0; | ||
7885 | return 0; | ||
7886 | } | ||
7887 | |||
7888 | static noinline int relocate_tree_block(struct btrfs_trans_handle *trans, | ||
7889 | struct btrfs_root *root, | ||
7890 | struct btrfs_path *path, | ||
7891 | struct btrfs_key *first_key, | ||
7892 | struct btrfs_ref_path *ref_path) | ||
7893 | { | ||
7894 | int ret; | ||
7895 | |||
7896 | ret = relocate_one_path(trans, root, path, first_key, | ||
7897 | ref_path, NULL, NULL); | ||
7898 | BUG_ON(ret); | ||
7899 | |||
7900 | return 0; | ||
7901 | } | ||
7902 | |||
7903 | static noinline int del_extent_zero(struct btrfs_trans_handle *trans, | ||
7904 | struct btrfs_root *extent_root, | ||
7905 | struct btrfs_path *path, | ||
7906 | struct btrfs_key *extent_key) | ||
7907 | { | ||
7908 | int ret; | ||
7909 | |||
7910 | ret = btrfs_search_slot(trans, extent_root, extent_key, path, -1, 1); | ||
7911 | if (ret) | ||
7912 | goto out; | ||
7913 | ret = btrfs_del_item(trans, extent_root, path); | ||
7914 | out: | ||
7915 | btrfs_release_path(extent_root, path); | ||
7916 | return ret; | ||
7917 | } | ||
7918 | |||
7919 | static noinline struct btrfs_root *read_ref_root(struct btrfs_fs_info *fs_info, | ||
7920 | struct btrfs_ref_path *ref_path) | ||
7921 | { | ||
7922 | struct btrfs_key root_key; | ||
7923 | |||
7924 | root_key.objectid = ref_path->root_objectid; | ||
7925 | root_key.type = BTRFS_ROOT_ITEM_KEY; | ||
7926 | if (is_cowonly_root(ref_path->root_objectid)) | ||
7927 | root_key.offset = 0; | ||
7928 | else | ||
7929 | root_key.offset = (u64)-1; | ||
7930 | |||
7931 | return btrfs_read_fs_root_no_name(fs_info, &root_key); | ||
7932 | } | ||
7933 | |||
7934 | static noinline int relocate_one_extent(struct btrfs_root *extent_root, | ||
7935 | struct btrfs_path *path, | ||
7936 | struct btrfs_key *extent_key, | ||
7937 | struct btrfs_block_group_cache *group, | ||
7938 | struct inode *reloc_inode, int pass) | ||
7939 | { | ||
7940 | struct btrfs_trans_handle *trans; | ||
7941 | struct btrfs_root *found_root; | ||
7942 | struct btrfs_ref_path *ref_path = NULL; | ||
7943 | struct disk_extent *new_extents = NULL; | ||
7944 | int nr_extents = 0; | ||
7945 | int loops; | ||
7946 | int ret; | ||
7947 | int level; | ||
7948 | struct btrfs_key first_key; | ||
7949 | u64 prev_block = 0; | ||
7950 | |||
7951 | |||
7952 | trans = btrfs_start_transaction(extent_root, 1); | ||
7953 | BUG_ON(IS_ERR(trans)); | ||
7954 | |||
7955 | if (extent_key->objectid == 0) { | ||
7956 | ret = del_extent_zero(trans, extent_root, path, extent_key); | ||
7957 | goto out; | ||
7958 | } | ||
7959 | |||
7960 | ref_path = kmalloc(sizeof(*ref_path), GFP_NOFS); | ||
7961 | if (!ref_path) { | ||
7962 | ret = -ENOMEM; | ||
7963 | goto out; | ||
7964 | } | ||
7965 | |||
7966 | for (loops = 0; ; loops++) { | ||
7967 | if (loops == 0) { | ||
7968 | ret = btrfs_first_ref_path(trans, extent_root, ref_path, | ||
7969 | extent_key->objectid); | ||
7970 | } else { | ||
7971 | ret = btrfs_next_ref_path(trans, extent_root, ref_path); | ||
7972 | } | ||
7973 | if (ret < 0) | ||
7974 | goto out; | ||
7975 | if (ret > 0) | ||
7976 | break; | ||
7977 | |||
7978 | if (ref_path->root_objectid == BTRFS_TREE_LOG_OBJECTID || | ||
7979 | ref_path->root_objectid == BTRFS_TREE_RELOC_OBJECTID) | ||
7980 | continue; | ||
7981 | |||
7982 | found_root = read_ref_root(extent_root->fs_info, ref_path); | ||
7983 | BUG_ON(!found_root); | ||
7984 | /* | ||
7985 | * for reference counted tree, only process reference paths | ||
7986 | * rooted at the latest committed root. | ||
7987 | */ | ||
7988 | if (found_root->ref_cows && | ||
7989 | ref_path->root_generation != found_root->root_key.offset) | ||
7990 | continue; | ||
7991 | |||
7992 | if (ref_path->owner_objectid >= BTRFS_FIRST_FREE_OBJECTID) { | ||
7993 | if (pass == 0) { | ||
7994 | /* | ||
7995 | * copy data extents to new locations | ||
7996 | */ | ||
7997 | u64 group_start = group->key.objectid; | ||
7998 | ret = relocate_data_extent(reloc_inode, | ||
7999 | extent_key, | ||
8000 | group_start); | ||
8001 | if (ret < 0) | ||
8002 | goto out; | ||
8003 | break; | ||
8004 | } | ||
8005 | level = 0; | ||
8006 | } else { | ||
8007 | level = ref_path->owner_objectid; | ||
8008 | } | ||
8009 | |||
8010 | if (prev_block != ref_path->nodes[level]) { | ||
8011 | struct extent_buffer *eb; | ||
8012 | u64 block_start = ref_path->nodes[level]; | ||
8013 | u64 block_size = btrfs_level_size(found_root, level); | ||
8014 | |||
8015 | eb = read_tree_block(found_root, block_start, | ||
8016 | block_size, 0); | ||
8017 | if (!eb) { | ||
8018 | ret = -EIO; | ||
8019 | goto out; | ||
8020 | } | ||
8021 | btrfs_tree_lock(eb); | ||
8022 | BUG_ON(level != btrfs_header_level(eb)); | ||
8023 | |||
8024 | if (level == 0) | ||
8025 | btrfs_item_key_to_cpu(eb, &first_key, 0); | ||
8026 | else | ||
8027 | btrfs_node_key_to_cpu(eb, &first_key, 0); | ||
8028 | |||
8029 | btrfs_tree_unlock(eb); | ||
8030 | free_extent_buffer(eb); | ||
8031 | prev_block = block_start; | ||
8032 | } | ||
8033 | |||
8034 | mutex_lock(&extent_root->fs_info->trans_mutex); | ||
8035 | btrfs_record_root_in_trans(found_root); | ||
8036 | mutex_unlock(&extent_root->fs_info->trans_mutex); | ||
8037 | if (ref_path->owner_objectid >= BTRFS_FIRST_FREE_OBJECTID) { | ||
8038 | /* | ||
8039 | * try to update data extent references while | ||
8040 | * keeping metadata shared between snapshots. | ||
8041 | */ | ||
8042 | if (pass == 1) { | ||
8043 | ret = relocate_one_path(trans, found_root, | ||
8044 | path, &first_key, ref_path, | ||
8045 | group, reloc_inode); | ||
8046 | if (ret < 0) | ||
8047 | goto out; | ||
8048 | continue; | ||
8049 | } | ||
8050 | /* | ||
8051 | * use fallback method to process the remaining | ||
8052 | * references. | ||
8053 | */ | ||
8054 | if (!new_extents) { | ||
8055 | u64 group_start = group->key.objectid; | ||
8056 | new_extents = kmalloc(sizeof(*new_extents), | ||
8057 | GFP_NOFS); | ||
8058 | if (!new_extents) { | ||
8059 | ret = -ENOMEM; | ||
8060 | goto out; | ||
8061 | } | ||
8062 | nr_extents = 1; | ||
8063 | ret = get_new_locations(reloc_inode, | ||
8064 | extent_key, | ||
8065 | group_start, 1, | ||
8066 | &new_extents, | ||
8067 | &nr_extents); | ||
8068 | if (ret) | ||
8069 | goto out; | ||
8070 | } | ||
8071 | ret = replace_one_extent(trans, found_root, | ||
8072 | path, extent_key, | ||
8073 | &first_key, ref_path, | ||
8074 | new_extents, nr_extents); | ||
8075 | } else { | ||
8076 | ret = relocate_tree_block(trans, found_root, path, | ||
8077 | &first_key, ref_path); | ||
8078 | } | ||
8079 | if (ret < 0) | ||
8080 | goto out; | ||
8081 | } | ||
8082 | ret = 0; | ||
8083 | out: | ||
8084 | btrfs_end_transaction(trans, extent_root); | ||
8085 | kfree(new_extents); | ||
8086 | kfree(ref_path); | ||
8087 | return ret; | ||
8088 | } | ||
8089 | #endif | ||
8090 | |||
8091 | static u64 update_block_group_flags(struct btrfs_root *root, u64 flags) | 6444 | static u64 update_block_group_flags(struct btrfs_root *root, u64 flags) |
8092 | { | 6445 | { |
8093 | u64 num_devices; | 6446 | u64 num_devices; |
@@ -8574,7 +6927,7 @@ int btrfs_read_block_groups(struct btrfs_root *root) | |||
8574 | memcpy(&cache->key, &found_key, sizeof(found_key)); | 6927 | memcpy(&cache->key, &found_key, sizeof(found_key)); |
8575 | 6928 | ||
8576 | key.objectid = found_key.objectid + found_key.offset; | 6929 | key.objectid = found_key.objectid + found_key.offset; |
8577 | btrfs_release_path(root, path); | 6930 | btrfs_release_path(path); |
8578 | cache->flags = btrfs_block_group_flags(&cache->item); | 6931 | cache->flags = btrfs_block_group_flags(&cache->item); |
8579 | cache->sectorsize = root->sectorsize; | 6932 | cache->sectorsize = root->sectorsize; |
8580 | 6933 | ||
@@ -8798,12 +7151,12 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, | |||
8798 | if (ret < 0) | 7151 | if (ret < 0) |
8799 | goto out; | 7152 | goto out; |
8800 | if (ret > 0) | 7153 | if (ret > 0) |
8801 | btrfs_release_path(tree_root, path); | 7154 | btrfs_release_path(path); |
8802 | if (ret == 0) { | 7155 | if (ret == 0) { |
8803 | ret = btrfs_del_item(trans, tree_root, path); | 7156 | ret = btrfs_del_item(trans, tree_root, path); |
8804 | if (ret) | 7157 | if (ret) |
8805 | goto out; | 7158 | goto out; |
8806 | btrfs_release_path(tree_root, path); | 7159 | btrfs_release_path(path); |
8807 | } | 7160 | } |
8808 | 7161 | ||
8809 | spin_lock(&root->fs_info->block_group_cache_lock); | 7162 | spin_lock(&root->fs_info->block_group_cache_lock); |
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 4bf90abea3d6..64c8b361b539 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -101,7 +101,7 @@ void extent_io_exit(void) | |||
101 | } | 101 | } |
102 | 102 | ||
103 | void extent_io_tree_init(struct extent_io_tree *tree, | 103 | void extent_io_tree_init(struct extent_io_tree *tree, |
104 | struct address_space *mapping, gfp_t mask) | 104 | struct address_space *mapping) |
105 | { | 105 | { |
106 | tree->state = RB_ROOT; | 106 | tree->state = RB_ROOT; |
107 | INIT_RADIX_TREE(&tree->buffer, GFP_ATOMIC); | 107 | INIT_RADIX_TREE(&tree->buffer, GFP_ATOMIC); |
@@ -941,13 +941,6 @@ int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end, | |||
941 | NULL, mask); | 941 | NULL, mask); |
942 | } | 942 | } |
943 | 943 | ||
944 | static int clear_extent_new(struct extent_io_tree *tree, u64 start, u64 end, | ||
945 | gfp_t mask) | ||
946 | { | ||
947 | return clear_extent_bit(tree, start, end, EXTENT_NEW, 0, 0, | ||
948 | NULL, mask); | ||
949 | } | ||
950 | |||
951 | int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, | 944 | int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, |
952 | struct extent_state **cached_state, gfp_t mask) | 945 | struct extent_state **cached_state, gfp_t mask) |
953 | { | 946 | { |
@@ -963,11 +956,6 @@ static int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, | |||
963 | cached_state, mask); | 956 | cached_state, mask); |
964 | } | 957 | } |
965 | 958 | ||
966 | int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end) | ||
967 | { | ||
968 | return wait_extent_bit(tree, start, end, EXTENT_WRITEBACK); | ||
969 | } | ||
970 | |||
971 | /* | 959 | /* |
972 | * either insert or lock state struct between start and end use mask to tell | 960 | * either insert or lock state struct between start and end use mask to tell |
973 | * us if waiting is desired. | 961 | * us if waiting is desired. |
@@ -1028,25 +1016,6 @@ int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask) | |||
1028 | } | 1016 | } |
1029 | 1017 | ||
1030 | /* | 1018 | /* |
1031 | * helper function to set pages and extents in the tree dirty | ||
1032 | */ | ||
1033 | int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end) | ||
1034 | { | ||
1035 | unsigned long index = start >> PAGE_CACHE_SHIFT; | ||
1036 | unsigned long end_index = end >> PAGE_CACHE_SHIFT; | ||
1037 | struct page *page; | ||
1038 | |||
1039 | while (index <= end_index) { | ||
1040 | page = find_get_page(tree->mapping, index); | ||
1041 | BUG_ON(!page); | ||
1042 | __set_page_dirty_nobuffers(page); | ||
1043 | page_cache_release(page); | ||
1044 | index++; | ||
1045 | } | ||
1046 | return 0; | ||
1047 | } | ||
1048 | |||
1049 | /* | ||
1050 | * helper function to set both pages and extents in the tree writeback | 1019 | * helper function to set both pages and extents in the tree writeback |
1051 | */ | 1020 | */ |
1052 | static int set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end) | 1021 | static int set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end) |
@@ -1819,46 +1788,6 @@ static void end_bio_extent_readpage(struct bio *bio, int err) | |||
1819 | bio_put(bio); | 1788 | bio_put(bio); |
1820 | } | 1789 | } |
1821 | 1790 | ||
1822 | /* | ||
1823 | * IO done from prepare_write is pretty simple, we just unlock | ||
1824 | * the structs in the extent tree when done, and set the uptodate bits | ||
1825 | * as appropriate. | ||
1826 | */ | ||
1827 | static void end_bio_extent_preparewrite(struct bio *bio, int err) | ||
1828 | { | ||
1829 | const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); | ||
1830 | struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; | ||
1831 | struct extent_io_tree *tree; | ||
1832 | u64 start; | ||
1833 | u64 end; | ||
1834 | |||
1835 | do { | ||
1836 | struct page *page = bvec->bv_page; | ||
1837 | struct extent_state *cached = NULL; | ||
1838 | tree = &BTRFS_I(page->mapping->host)->io_tree; | ||
1839 | |||
1840 | start = ((u64)page->index << PAGE_CACHE_SHIFT) + | ||
1841 | bvec->bv_offset; | ||
1842 | end = start + bvec->bv_len - 1; | ||
1843 | |||
1844 | if (--bvec >= bio->bi_io_vec) | ||
1845 | prefetchw(&bvec->bv_page->flags); | ||
1846 | |||
1847 | if (uptodate) { | ||
1848 | set_extent_uptodate(tree, start, end, &cached, | ||
1849 | GFP_ATOMIC); | ||
1850 | } else { | ||
1851 | ClearPageUptodate(page); | ||
1852 | SetPageError(page); | ||
1853 | } | ||
1854 | |||
1855 | unlock_extent_cached(tree, start, end, &cached, GFP_ATOMIC); | ||
1856 | |||
1857 | } while (bvec >= bio->bi_io_vec); | ||
1858 | |||
1859 | bio_put(bio); | ||
1860 | } | ||
1861 | |||
1862 | struct bio * | 1791 | struct bio * |
1863 | btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, | 1792 | btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, |
1864 | gfp_t gfp_flags) | 1793 | gfp_t gfp_flags) |
@@ -2007,7 +1936,7 @@ static int __extent_read_full_page(struct extent_io_tree *tree, | |||
2007 | struct btrfs_ordered_extent *ordered; | 1936 | struct btrfs_ordered_extent *ordered; |
2008 | int ret; | 1937 | int ret; |
2009 | int nr = 0; | 1938 | int nr = 0; |
2010 | size_t page_offset = 0; | 1939 | size_t pg_offset = 0; |
2011 | size_t iosize; | 1940 | size_t iosize; |
2012 | size_t disk_io_size; | 1941 | size_t disk_io_size; |
2013 | size_t blocksize = inode->i_sb->s_blocksize; | 1942 | size_t blocksize = inode->i_sb->s_blocksize; |
@@ -2043,9 +1972,9 @@ static int __extent_read_full_page(struct extent_io_tree *tree, | |||
2043 | char *userpage; | 1972 | char *userpage; |
2044 | struct extent_state *cached = NULL; | 1973 | struct extent_state *cached = NULL; |
2045 | 1974 | ||
2046 | iosize = PAGE_CACHE_SIZE - page_offset; | 1975 | iosize = PAGE_CACHE_SIZE - pg_offset; |
2047 | userpage = kmap_atomic(page, KM_USER0); | 1976 | userpage = kmap_atomic(page, KM_USER0); |
2048 | memset(userpage + page_offset, 0, iosize); | 1977 | memset(userpage + pg_offset, 0, iosize); |
2049 | flush_dcache_page(page); | 1978 | flush_dcache_page(page); |
2050 | kunmap_atomic(userpage, KM_USER0); | 1979 | kunmap_atomic(userpage, KM_USER0); |
2051 | set_extent_uptodate(tree, cur, cur + iosize - 1, | 1980 | set_extent_uptodate(tree, cur, cur + iosize - 1, |
@@ -2054,9 +1983,9 @@ static int __extent_read_full_page(struct extent_io_tree *tree, | |||
2054 | &cached, GFP_NOFS); | 1983 | &cached, GFP_NOFS); |
2055 | break; | 1984 | break; |
2056 | } | 1985 | } |
2057 | em = get_extent(inode, page, page_offset, cur, | 1986 | em = get_extent(inode, page, pg_offset, cur, |
2058 | end - cur + 1, 0); | 1987 | end - cur + 1, 0); |
2059 | if (IS_ERR(em) || !em) { | 1988 | if (IS_ERR_OR_NULL(em)) { |
2060 | SetPageError(page); | 1989 | SetPageError(page); |
2061 | unlock_extent(tree, cur, end, GFP_NOFS); | 1990 | unlock_extent(tree, cur, end, GFP_NOFS); |
2062 | break; | 1991 | break; |
@@ -2094,7 +2023,7 @@ static int __extent_read_full_page(struct extent_io_tree *tree, | |||
2094 | struct extent_state *cached = NULL; | 2023 | struct extent_state *cached = NULL; |
2095 | 2024 | ||
2096 | userpage = kmap_atomic(page, KM_USER0); | 2025 | userpage = kmap_atomic(page, KM_USER0); |
2097 | memset(userpage + page_offset, 0, iosize); | 2026 | memset(userpage + pg_offset, 0, iosize); |
2098 | flush_dcache_page(page); | 2027 | flush_dcache_page(page); |
2099 | kunmap_atomic(userpage, KM_USER0); | 2028 | kunmap_atomic(userpage, KM_USER0); |
2100 | 2029 | ||
@@ -2103,7 +2032,7 @@ static int __extent_read_full_page(struct extent_io_tree *tree, | |||
2103 | unlock_extent_cached(tree, cur, cur + iosize - 1, | 2032 | unlock_extent_cached(tree, cur, cur + iosize - 1, |
2104 | &cached, GFP_NOFS); | 2033 | &cached, GFP_NOFS); |
2105 | cur = cur + iosize; | 2034 | cur = cur + iosize; |
2106 | page_offset += iosize; | 2035 | pg_offset += iosize; |
2107 | continue; | 2036 | continue; |
2108 | } | 2037 | } |
2109 | /* the get_extent function already copied into the page */ | 2038 | /* the get_extent function already copied into the page */ |
@@ -2112,7 +2041,7 @@ static int __extent_read_full_page(struct extent_io_tree *tree, | |||
2112 | check_page_uptodate(tree, page); | 2041 | check_page_uptodate(tree, page); |
2113 | unlock_extent(tree, cur, cur + iosize - 1, GFP_NOFS); | 2042 | unlock_extent(tree, cur, cur + iosize - 1, GFP_NOFS); |
2114 | cur = cur + iosize; | 2043 | cur = cur + iosize; |
2115 | page_offset += iosize; | 2044 | pg_offset += iosize; |
2116 | continue; | 2045 | continue; |
2117 | } | 2046 | } |
2118 | /* we have an inline extent but it didn't get marked up | 2047 | /* we have an inline extent but it didn't get marked up |
@@ -2122,7 +2051,7 @@ static int __extent_read_full_page(struct extent_io_tree *tree, | |||
2122 | SetPageError(page); | 2051 | SetPageError(page); |
2123 | unlock_extent(tree, cur, cur + iosize - 1, GFP_NOFS); | 2052 | unlock_extent(tree, cur, cur + iosize - 1, GFP_NOFS); |
2124 | cur = cur + iosize; | 2053 | cur = cur + iosize; |
2125 | page_offset += iosize; | 2054 | pg_offset += iosize; |
2126 | continue; | 2055 | continue; |
2127 | } | 2056 | } |
2128 | 2057 | ||
@@ -2135,7 +2064,7 @@ static int __extent_read_full_page(struct extent_io_tree *tree, | |||
2135 | unsigned long pnr = (last_byte >> PAGE_CACHE_SHIFT) + 1; | 2064 | unsigned long pnr = (last_byte >> PAGE_CACHE_SHIFT) + 1; |
2136 | pnr -= page->index; | 2065 | pnr -= page->index; |
2137 | ret = submit_extent_page(READ, tree, page, | 2066 | ret = submit_extent_page(READ, tree, page, |
2138 | sector, disk_io_size, page_offset, | 2067 | sector, disk_io_size, pg_offset, |
2139 | bdev, bio, pnr, | 2068 | bdev, bio, pnr, |
2140 | end_bio_extent_readpage, mirror_num, | 2069 | end_bio_extent_readpage, mirror_num, |
2141 | *bio_flags, | 2070 | *bio_flags, |
@@ -2146,7 +2075,7 @@ static int __extent_read_full_page(struct extent_io_tree *tree, | |||
2146 | if (ret) | 2075 | if (ret) |
2147 | SetPageError(page); | 2076 | SetPageError(page); |
2148 | cur = cur + iosize; | 2077 | cur = cur + iosize; |
2149 | page_offset += iosize; | 2078 | pg_offset += iosize; |
2150 | } | 2079 | } |
2151 | if (!nr) { | 2080 | if (!nr) { |
2152 | if (!PageError(page)) | 2081 | if (!PageError(page)) |
@@ -2341,7 +2270,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, | |||
2341 | } | 2270 | } |
2342 | em = epd->get_extent(inode, page, pg_offset, cur, | 2271 | em = epd->get_extent(inode, page, pg_offset, cur, |
2343 | end - cur + 1, 1); | 2272 | end - cur + 1, 1); |
2344 | if (IS_ERR(em) || !em) { | 2273 | if (IS_ERR_OR_NULL(em)) { |
2345 | SetPageError(page); | 2274 | SetPageError(page); |
2346 | break; | 2275 | break; |
2347 | } | 2276 | } |
@@ -2720,128 +2649,6 @@ int extent_invalidatepage(struct extent_io_tree *tree, | |||
2720 | } | 2649 | } |
2721 | 2650 | ||
2722 | /* | 2651 | /* |
2723 | * simple commit_write call, set_range_dirty is used to mark both | ||
2724 | * the pages and the extent records as dirty | ||
2725 | */ | ||
2726 | int extent_commit_write(struct extent_io_tree *tree, | ||
2727 | struct inode *inode, struct page *page, | ||
2728 | unsigned from, unsigned to) | ||
2729 | { | ||
2730 | loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to; | ||
2731 | |||
2732 | set_page_extent_mapped(page); | ||
2733 | set_page_dirty(page); | ||
2734 | |||
2735 | if (pos > inode->i_size) { | ||
2736 | i_size_write(inode, pos); | ||
2737 | mark_inode_dirty(inode); | ||
2738 | } | ||
2739 | return 0; | ||
2740 | } | ||
2741 | |||
2742 | int extent_prepare_write(struct extent_io_tree *tree, | ||
2743 | struct inode *inode, struct page *page, | ||
2744 | unsigned from, unsigned to, get_extent_t *get_extent) | ||
2745 | { | ||
2746 | u64 page_start = (u64)page->index << PAGE_CACHE_SHIFT; | ||
2747 | u64 page_end = page_start + PAGE_CACHE_SIZE - 1; | ||
2748 | u64 block_start; | ||
2749 | u64 orig_block_start; | ||
2750 | u64 block_end; | ||
2751 | u64 cur_end; | ||
2752 | struct extent_map *em; | ||
2753 | unsigned blocksize = 1 << inode->i_blkbits; | ||
2754 | size_t page_offset = 0; | ||
2755 | size_t block_off_start; | ||
2756 | size_t block_off_end; | ||
2757 | int err = 0; | ||
2758 | int iocount = 0; | ||
2759 | int ret = 0; | ||
2760 | int isnew; | ||
2761 | |||
2762 | set_page_extent_mapped(page); | ||
2763 | |||
2764 | block_start = (page_start + from) & ~((u64)blocksize - 1); | ||
2765 | block_end = (page_start + to - 1) | (blocksize - 1); | ||
2766 | orig_block_start = block_start; | ||
2767 | |||
2768 | lock_extent(tree, page_start, page_end, GFP_NOFS); | ||
2769 | while (block_start <= block_end) { | ||
2770 | em = get_extent(inode, page, page_offset, block_start, | ||
2771 | block_end - block_start + 1, 1); | ||
2772 | if (IS_ERR(em) || !em) | ||
2773 | goto err; | ||
2774 | |||
2775 | cur_end = min(block_end, extent_map_end(em) - 1); | ||
2776 | block_off_start = block_start & (PAGE_CACHE_SIZE - 1); | ||
2777 | block_off_end = block_off_start + blocksize; | ||
2778 | isnew = clear_extent_new(tree, block_start, cur_end, GFP_NOFS); | ||
2779 | |||
2780 | if (!PageUptodate(page) && isnew && | ||
2781 | (block_off_end > to || block_off_start < from)) { | ||
2782 | void *kaddr; | ||
2783 | |||
2784 | kaddr = kmap_atomic(page, KM_USER0); | ||
2785 | if (block_off_end > to) | ||
2786 | memset(kaddr + to, 0, block_off_end - to); | ||
2787 | if (block_off_start < from) | ||
2788 | memset(kaddr + block_off_start, 0, | ||
2789 | from - block_off_start); | ||
2790 | flush_dcache_page(page); | ||
2791 | kunmap_atomic(kaddr, KM_USER0); | ||
2792 | } | ||
2793 | if ((em->block_start != EXTENT_MAP_HOLE && | ||
2794 | em->block_start != EXTENT_MAP_INLINE) && | ||
2795 | !isnew && !PageUptodate(page) && | ||
2796 | (block_off_end > to || block_off_start < from) && | ||
2797 | !test_range_bit(tree, block_start, cur_end, | ||
2798 | EXTENT_UPTODATE, 1, NULL)) { | ||
2799 | u64 sector; | ||
2800 | u64 extent_offset = block_start - em->start; | ||
2801 | size_t iosize; | ||
2802 | sector = (em->block_start + extent_offset) >> 9; | ||
2803 | iosize = (cur_end - block_start + blocksize) & | ||
2804 | ~((u64)blocksize - 1); | ||
2805 | /* | ||
2806 | * we've already got the extent locked, but we | ||
2807 | * need to split the state such that our end_bio | ||
2808 | * handler can clear the lock. | ||
2809 | */ | ||
2810 | set_extent_bit(tree, block_start, | ||
2811 | block_start + iosize - 1, | ||
2812 | EXTENT_LOCKED, 0, NULL, NULL, GFP_NOFS); | ||
2813 | ret = submit_extent_page(READ, tree, page, | ||
2814 | sector, iosize, page_offset, em->bdev, | ||
2815 | NULL, 1, | ||
2816 | end_bio_extent_preparewrite, 0, | ||
2817 | 0, 0); | ||
2818 | if (ret && !err) | ||
2819 | err = ret; | ||
2820 | iocount++; | ||
2821 | block_start = block_start + iosize; | ||
2822 | } else { | ||
2823 | struct extent_state *cached = NULL; | ||
2824 | |||
2825 | set_extent_uptodate(tree, block_start, cur_end, &cached, | ||
2826 | GFP_NOFS); | ||
2827 | unlock_extent_cached(tree, block_start, cur_end, | ||
2828 | &cached, GFP_NOFS); | ||
2829 | block_start = cur_end + 1; | ||
2830 | } | ||
2831 | page_offset = block_start & (PAGE_CACHE_SIZE - 1); | ||
2832 | free_extent_map(em); | ||
2833 | } | ||
2834 | if (iocount) { | ||
2835 | wait_extent_bit(tree, orig_block_start, | ||
2836 | block_end, EXTENT_LOCKED); | ||
2837 | } | ||
2838 | check_page_uptodate(tree, page); | ||
2839 | err: | ||
2840 | /* FIXME, zero out newly allocated blocks on error */ | ||
2841 | return err; | ||
2842 | } | ||
2843 | |||
2844 | /* | ||
2845 | * a helper for releasepage, this tests for areas of the page that | 2652 | * a helper for releasepage, this tests for areas of the page that |
2846 | * are locked or under IO and drops the related state bits if it is safe | 2653 | * are locked or under IO and drops the related state bits if it is safe |
2847 | * to drop the page. | 2654 | * to drop the page. |
@@ -2899,7 +2706,7 @@ int try_release_extent_mapping(struct extent_map_tree *map, | |||
2899 | len = end - start + 1; | 2706 | len = end - start + 1; |
2900 | write_lock(&map->lock); | 2707 | write_lock(&map->lock); |
2901 | em = lookup_extent_mapping(map, start, len); | 2708 | em = lookup_extent_mapping(map, start, len); |
2902 | if (!em || IS_ERR(em)) { | 2709 | if (IS_ERR_OR_NULL(em)) { |
2903 | write_unlock(&map->lock); | 2710 | write_unlock(&map->lock); |
2904 | break; | 2711 | break; |
2905 | } | 2712 | } |
@@ -2927,33 +2734,6 @@ int try_release_extent_mapping(struct extent_map_tree *map, | |||
2927 | return try_release_extent_state(map, tree, page, mask); | 2734 | return try_release_extent_state(map, tree, page, mask); |
2928 | } | 2735 | } |
2929 | 2736 | ||
2930 | sector_t extent_bmap(struct address_space *mapping, sector_t iblock, | ||
2931 | get_extent_t *get_extent) | ||
2932 | { | ||
2933 | struct inode *inode = mapping->host; | ||
2934 | struct extent_state *cached_state = NULL; | ||
2935 | u64 start = iblock << inode->i_blkbits; | ||
2936 | sector_t sector = 0; | ||
2937 | size_t blksize = (1 << inode->i_blkbits); | ||
2938 | struct extent_map *em; | ||
2939 | |||
2940 | lock_extent_bits(&BTRFS_I(inode)->io_tree, start, start + blksize - 1, | ||
2941 | 0, &cached_state, GFP_NOFS); | ||
2942 | em = get_extent(inode, NULL, 0, start, blksize, 0); | ||
2943 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, start, | ||
2944 | start + blksize - 1, &cached_state, GFP_NOFS); | ||
2945 | if (!em || IS_ERR(em)) | ||
2946 | return 0; | ||
2947 | |||
2948 | if (em->block_start > EXTENT_MAP_LAST_BYTE) | ||
2949 | goto out; | ||
2950 | |||
2951 | sector = (em->block_start + start - em->start) >> inode->i_blkbits; | ||
2952 | out: | ||
2953 | free_extent_map(em); | ||
2954 | return sector; | ||
2955 | } | ||
2956 | |||
2957 | /* | 2737 | /* |
2958 | * helper function for fiemap, which doesn't want to see any holes. | 2738 | * helper function for fiemap, which doesn't want to see any holes. |
2959 | * This maps until we find something past 'last' | 2739 | * This maps until we find something past 'last' |
@@ -2976,7 +2756,7 @@ static struct extent_map *get_extent_skip_holes(struct inode *inode, | |||
2976 | break; | 2756 | break; |
2977 | len = (len + sectorsize - 1) & ~(sectorsize - 1); | 2757 | len = (len + sectorsize - 1) & ~(sectorsize - 1); |
2978 | em = get_extent(inode, NULL, 0, offset, len, 0); | 2758 | em = get_extent(inode, NULL, 0, offset, len, 0); |
2979 | if (!em || IS_ERR(em)) | 2759 | if (IS_ERR_OR_NULL(em)) |
2980 | return em; | 2760 | return em; |
2981 | 2761 | ||
2982 | /* if this isn't a hole return it */ | 2762 | /* if this isn't a hole return it */ |
@@ -3266,8 +3046,7 @@ static inline void btrfs_release_extent_buffer(struct extent_buffer *eb) | |||
3266 | 3046 | ||
3267 | struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, | 3047 | struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, |
3268 | u64 start, unsigned long len, | 3048 | u64 start, unsigned long len, |
3269 | struct page *page0, | 3049 | struct page *page0) |
3270 | gfp_t mask) | ||
3271 | { | 3050 | { |
3272 | unsigned long num_pages = num_extent_pages(start, len); | 3051 | unsigned long num_pages = num_extent_pages(start, len); |
3273 | unsigned long i; | 3052 | unsigned long i; |
@@ -3288,7 +3067,7 @@ struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, | |||
3288 | } | 3067 | } |
3289 | rcu_read_unlock(); | 3068 | rcu_read_unlock(); |
3290 | 3069 | ||
3291 | eb = __alloc_extent_buffer(tree, start, len, mask); | 3070 | eb = __alloc_extent_buffer(tree, start, len, GFP_NOFS); |
3292 | if (!eb) | 3071 | if (!eb) |
3293 | return NULL; | 3072 | return NULL; |
3294 | 3073 | ||
@@ -3305,7 +3084,7 @@ struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, | |||
3305 | i = 0; | 3084 | i = 0; |
3306 | } | 3085 | } |
3307 | for (; i < num_pages; i++, index++) { | 3086 | for (; i < num_pages; i++, index++) { |
3308 | p = find_or_create_page(mapping, index, mask | __GFP_HIGHMEM); | 3087 | p = find_or_create_page(mapping, index, GFP_NOFS | __GFP_HIGHMEM); |
3309 | if (!p) { | 3088 | if (!p) { |
3310 | WARN_ON(1); | 3089 | WARN_ON(1); |
3311 | goto free_eb; | 3090 | goto free_eb; |
@@ -3377,8 +3156,7 @@ free_eb: | |||
3377 | } | 3156 | } |
3378 | 3157 | ||
3379 | struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree, | 3158 | struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree, |
3380 | u64 start, unsigned long len, | 3159 | u64 start, unsigned long len) |
3381 | gfp_t mask) | ||
3382 | { | 3160 | { |
3383 | struct extent_buffer *eb; | 3161 | struct extent_buffer *eb; |
3384 | 3162 | ||
@@ -3439,13 +3217,6 @@ int clear_extent_buffer_dirty(struct extent_io_tree *tree, | |||
3439 | return 0; | 3217 | return 0; |
3440 | } | 3218 | } |
3441 | 3219 | ||
3442 | int wait_on_extent_buffer_writeback(struct extent_io_tree *tree, | ||
3443 | struct extent_buffer *eb) | ||
3444 | { | ||
3445 | return wait_on_extent_writeback(tree, eb->start, | ||
3446 | eb->start + eb->len - 1); | ||
3447 | } | ||
3448 | |||
3449 | int set_extent_buffer_dirty(struct extent_io_tree *tree, | 3220 | int set_extent_buffer_dirty(struct extent_io_tree *tree, |
3450 | struct extent_buffer *eb) | 3221 | struct extent_buffer *eb) |
3451 | { | 3222 | { |
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index af2d7179c372..4e8445a4757c 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h | |||
@@ -153,23 +153,14 @@ static inline int extent_compress_type(unsigned long bio_flags) | |||
153 | 153 | ||
154 | struct extent_map_tree; | 154 | struct extent_map_tree; |
155 | 155 | ||
156 | static inline struct extent_state *extent_state_next(struct extent_state *state) | ||
157 | { | ||
158 | struct rb_node *node; | ||
159 | node = rb_next(&state->rb_node); | ||
160 | if (!node) | ||
161 | return NULL; | ||
162 | return rb_entry(node, struct extent_state, rb_node); | ||
163 | } | ||
164 | |||
165 | typedef struct extent_map *(get_extent_t)(struct inode *inode, | 156 | typedef struct extent_map *(get_extent_t)(struct inode *inode, |
166 | struct page *page, | 157 | struct page *page, |
167 | size_t page_offset, | 158 | size_t pg_offset, |
168 | u64 start, u64 len, | 159 | u64 start, u64 len, |
169 | int create); | 160 | int create); |
170 | 161 | ||
171 | void extent_io_tree_init(struct extent_io_tree *tree, | 162 | void extent_io_tree_init(struct extent_io_tree *tree, |
172 | struct address_space *mapping, gfp_t mask); | 163 | struct address_space *mapping); |
173 | int try_release_extent_mapping(struct extent_map_tree *map, | 164 | int try_release_extent_mapping(struct extent_map_tree *map, |
174 | struct extent_io_tree *tree, struct page *page, | 165 | struct extent_io_tree *tree, struct page *page, |
175 | gfp_t mask); | 166 | gfp_t mask); |
@@ -215,14 +206,8 @@ int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, | |||
215 | gfp_t mask); | 206 | gfp_t mask); |
216 | int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, | 207 | int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, |
217 | gfp_t mask); | 208 | gfp_t mask); |
218 | int clear_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end, | ||
219 | gfp_t mask); | ||
220 | int clear_extent_ordered_metadata(struct extent_io_tree *tree, u64 start, | ||
221 | u64 end, gfp_t mask); | ||
222 | int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end, | 209 | int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end, |
223 | struct extent_state **cached_state, gfp_t mask); | 210 | struct extent_state **cached_state, gfp_t mask); |
224 | int set_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end, | ||
225 | gfp_t mask); | ||
226 | int find_first_extent_bit(struct extent_io_tree *tree, u64 start, | 211 | int find_first_extent_bit(struct extent_io_tree *tree, u64 start, |
227 | u64 *start_ret, u64 *end_ret, int bits); | 212 | u64 *start_ret, u64 *end_ret, int bits); |
228 | struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree, | 213 | struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree, |
@@ -243,28 +228,17 @@ int extent_readpages(struct extent_io_tree *tree, | |||
243 | struct address_space *mapping, | 228 | struct address_space *mapping, |
244 | struct list_head *pages, unsigned nr_pages, | 229 | struct list_head *pages, unsigned nr_pages, |
245 | get_extent_t get_extent); | 230 | get_extent_t get_extent); |
246 | int extent_prepare_write(struct extent_io_tree *tree, | ||
247 | struct inode *inode, struct page *page, | ||
248 | unsigned from, unsigned to, get_extent_t *get_extent); | ||
249 | int extent_commit_write(struct extent_io_tree *tree, | ||
250 | struct inode *inode, struct page *page, | ||
251 | unsigned from, unsigned to); | ||
252 | sector_t extent_bmap(struct address_space *mapping, sector_t iblock, | ||
253 | get_extent_t *get_extent); | ||
254 | int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | 231 | int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
255 | __u64 start, __u64 len, get_extent_t *get_extent); | 232 | __u64 start, __u64 len, get_extent_t *get_extent); |
256 | int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end); | ||
257 | int set_state_private(struct extent_io_tree *tree, u64 start, u64 private); | 233 | int set_state_private(struct extent_io_tree *tree, u64 start, u64 private); |
258 | int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private); | 234 | int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private); |
259 | void set_page_extent_mapped(struct page *page); | 235 | void set_page_extent_mapped(struct page *page); |
260 | 236 | ||
261 | struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, | 237 | struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, |
262 | u64 start, unsigned long len, | 238 | u64 start, unsigned long len, |
263 | struct page *page0, | 239 | struct page *page0); |
264 | gfp_t mask); | ||
265 | struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree, | 240 | struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree, |
266 | u64 start, unsigned long len, | 241 | u64 start, unsigned long len); |
267 | gfp_t mask); | ||
268 | void free_extent_buffer(struct extent_buffer *eb); | 242 | void free_extent_buffer(struct extent_buffer *eb); |
269 | int read_extent_buffer_pages(struct extent_io_tree *tree, | 243 | int read_extent_buffer_pages(struct extent_io_tree *tree, |
270 | struct extent_buffer *eb, u64 start, int wait, | 244 | struct extent_buffer *eb, u64 start, int wait, |
@@ -292,16 +266,11 @@ void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, | |||
292 | unsigned long src_offset, unsigned long len); | 266 | unsigned long src_offset, unsigned long len); |
293 | void memset_extent_buffer(struct extent_buffer *eb, char c, | 267 | void memset_extent_buffer(struct extent_buffer *eb, char c, |
294 | unsigned long start, unsigned long len); | 268 | unsigned long start, unsigned long len); |
295 | int wait_on_extent_buffer_writeback(struct extent_io_tree *tree, | ||
296 | struct extent_buffer *eb); | ||
297 | int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end); | ||
298 | int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits); | 269 | int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits); |
299 | int clear_extent_buffer_dirty(struct extent_io_tree *tree, | 270 | int clear_extent_buffer_dirty(struct extent_io_tree *tree, |
300 | struct extent_buffer *eb); | 271 | struct extent_buffer *eb); |
301 | int set_extent_buffer_dirty(struct extent_io_tree *tree, | 272 | int set_extent_buffer_dirty(struct extent_io_tree *tree, |
302 | struct extent_buffer *eb); | 273 | struct extent_buffer *eb); |
303 | int test_extent_buffer_dirty(struct extent_io_tree *tree, | ||
304 | struct extent_buffer *eb); | ||
305 | int set_extent_buffer_uptodate(struct extent_io_tree *tree, | 274 | int set_extent_buffer_uptodate(struct extent_io_tree *tree, |
306 | struct extent_buffer *eb); | 275 | struct extent_buffer *eb); |
307 | int clear_extent_buffer_uptodate(struct extent_io_tree *tree, | 276 | int clear_extent_buffer_uptodate(struct extent_io_tree *tree, |
@@ -319,7 +288,6 @@ int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset, | |||
319 | unsigned long *map_start, | 288 | unsigned long *map_start, |
320 | unsigned long *map_len, int km); | 289 | unsigned long *map_len, int km); |
321 | void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km); | 290 | void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km); |
322 | int release_extent_buffer_tail_pages(struct extent_buffer *eb); | ||
323 | int extent_range_uptodate(struct extent_io_tree *tree, | 291 | int extent_range_uptodate(struct extent_io_tree *tree, |
324 | u64 start, u64 end); | 292 | u64 start, u64 end); |
325 | int extent_clear_unlock_delalloc(struct inode *inode, | 293 | int extent_clear_unlock_delalloc(struct inode *inode, |
diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index a24a3f2fa13e..2d0410344ea3 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c | |||
@@ -28,12 +28,11 @@ void extent_map_exit(void) | |||
28 | /** | 28 | /** |
29 | * extent_map_tree_init - initialize extent map tree | 29 | * extent_map_tree_init - initialize extent map tree |
30 | * @tree: tree to initialize | 30 | * @tree: tree to initialize |
31 | * @mask: flags for memory allocations during tree operations | ||
32 | * | 31 | * |
33 | * Initialize the extent tree @tree. Should be called for each new inode | 32 | * Initialize the extent tree @tree. Should be called for each new inode |
34 | * or other user of the extent_map interface. | 33 | * or other user of the extent_map interface. |
35 | */ | 34 | */ |
36 | void extent_map_tree_init(struct extent_map_tree *tree, gfp_t mask) | 35 | void extent_map_tree_init(struct extent_map_tree *tree) |
37 | { | 36 | { |
38 | tree->map = RB_ROOT; | 37 | tree->map = RB_ROOT; |
39 | rwlock_init(&tree->lock); | 38 | rwlock_init(&tree->lock); |
@@ -41,16 +40,15 @@ void extent_map_tree_init(struct extent_map_tree *tree, gfp_t mask) | |||
41 | 40 | ||
42 | /** | 41 | /** |
43 | * alloc_extent_map - allocate new extent map structure | 42 | * alloc_extent_map - allocate new extent map structure |
44 | * @mask: memory allocation flags | ||
45 | * | 43 | * |
46 | * Allocate a new extent_map structure. The new structure is | 44 | * Allocate a new extent_map structure. The new structure is |
47 | * returned with a reference count of one and needs to be | 45 | * returned with a reference count of one and needs to be |
48 | * freed using free_extent_map() | 46 | * freed using free_extent_map() |
49 | */ | 47 | */ |
50 | struct extent_map *alloc_extent_map(gfp_t mask) | 48 | struct extent_map *alloc_extent_map(void) |
51 | { | 49 | { |
52 | struct extent_map *em; | 50 | struct extent_map *em; |
53 | em = kmem_cache_alloc(extent_map_cache, mask); | 51 | em = kmem_cache_alloc(extent_map_cache, GFP_NOFS); |
54 | if (!em) | 52 | if (!em) |
55 | return NULL; | 53 | return NULL; |
56 | em->in_tree = 0; | 54 | em->in_tree = 0; |
diff --git a/fs/btrfs/extent_map.h b/fs/btrfs/extent_map.h index 28b44dbd1e35..33a7890b1f40 100644 --- a/fs/btrfs/extent_map.h +++ b/fs/btrfs/extent_map.h | |||
@@ -49,14 +49,14 @@ static inline u64 extent_map_block_end(struct extent_map *em) | |||
49 | return em->block_start + em->block_len; | 49 | return em->block_start + em->block_len; |
50 | } | 50 | } |
51 | 51 | ||
52 | void extent_map_tree_init(struct extent_map_tree *tree, gfp_t mask); | 52 | void extent_map_tree_init(struct extent_map_tree *tree); |
53 | struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, | 53 | struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, |
54 | u64 start, u64 len); | 54 | u64 start, u64 len); |
55 | int add_extent_mapping(struct extent_map_tree *tree, | 55 | int add_extent_mapping(struct extent_map_tree *tree, |
56 | struct extent_map *em); | 56 | struct extent_map *em); |
57 | int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em); | 57 | int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em); |
58 | 58 | ||
59 | struct extent_map *alloc_extent_map(gfp_t mask); | 59 | struct extent_map *alloc_extent_map(void); |
60 | void free_extent_map(struct extent_map *em); | 60 | void free_extent_map(struct extent_map *em); |
61 | int __init extent_map_init(void); | 61 | int __init extent_map_init(void); |
62 | void extent_map_exit(void); | 62 | void extent_map_exit(void); |
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 1d9410e39212..29e014984f60 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -193,7 +193,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, | |||
193 | u32 item_size; | 193 | u32 item_size; |
194 | 194 | ||
195 | if (item) | 195 | if (item) |
196 | btrfs_release_path(root, path); | 196 | btrfs_release_path(path); |
197 | item = btrfs_lookup_csum(NULL, root->fs_info->csum_root, | 197 | item = btrfs_lookup_csum(NULL, root->fs_info->csum_root, |
198 | path, disk_bytenr, 0); | 198 | path, disk_bytenr, 0); |
199 | if (IS_ERR(item)) { | 199 | if (IS_ERR(item)) { |
@@ -214,7 +214,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, | |||
214 | (unsigned long long)offset); | 214 | (unsigned long long)offset); |
215 | } | 215 | } |
216 | item = NULL; | 216 | item = NULL; |
217 | btrfs_release_path(root, path); | 217 | btrfs_release_path(path); |
218 | goto found; | 218 | goto found; |
219 | } | 219 | } |
220 | btrfs_item_key_to_cpu(path->nodes[0], &found_key, | 220 | btrfs_item_key_to_cpu(path->nodes[0], &found_key, |
@@ -632,7 +632,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, | |||
632 | if (key.offset < bytenr) | 632 | if (key.offset < bytenr) |
633 | break; | 633 | break; |
634 | } | 634 | } |
635 | btrfs_release_path(root, path); | 635 | btrfs_release_path(path); |
636 | } | 636 | } |
637 | out: | 637 | out: |
638 | btrfs_free_path(path); | 638 | btrfs_free_path(path); |
@@ -723,7 +723,7 @@ again: | |||
723 | * at this point, we know the tree has an item, but it isn't big | 723 | * at this point, we know the tree has an item, but it isn't big |
724 | * enough yet to put our csum in. Grow it | 724 | * enough yet to put our csum in. Grow it |
725 | */ | 725 | */ |
726 | btrfs_release_path(root, path); | 726 | btrfs_release_path(path); |
727 | ret = btrfs_search_slot(trans, root, &file_key, path, | 727 | ret = btrfs_search_slot(trans, root, &file_key, path, |
728 | csum_size, 1); | 728 | csum_size, 1); |
729 | if (ret < 0) | 729 | if (ret < 0) |
@@ -767,7 +767,7 @@ again: | |||
767 | } | 767 | } |
768 | 768 | ||
769 | insert: | 769 | insert: |
770 | btrfs_release_path(root, path); | 770 | btrfs_release_path(path); |
771 | csum_offset = 0; | 771 | csum_offset = 0; |
772 | if (found_next) { | 772 | if (found_next) { |
773 | u64 tmp = total_bytes + root->sectorsize; | 773 | u64 tmp = total_bytes + root->sectorsize; |
@@ -851,7 +851,7 @@ next_sector: | |||
851 | } | 851 | } |
852 | btrfs_mark_buffer_dirty(path->nodes[0]); | 852 | btrfs_mark_buffer_dirty(path->nodes[0]); |
853 | if (total_bytes < sums->len) { | 853 | if (total_bytes < sums->len) { |
854 | btrfs_release_path(root, path); | 854 | btrfs_release_path(path); |
855 | cond_resched(); | 855 | cond_resched(); |
856 | goto again; | 856 | goto again; |
857 | } | 857 | } |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index bef020451525..58ddc4442159 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -191,9 +191,9 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, | |||
191 | } | 191 | } |
192 | while (1) { | 192 | while (1) { |
193 | if (!split) | 193 | if (!split) |
194 | split = alloc_extent_map(GFP_NOFS); | 194 | split = alloc_extent_map(); |
195 | if (!split2) | 195 | if (!split2) |
196 | split2 = alloc_extent_map(GFP_NOFS); | 196 | split2 = alloc_extent_map(); |
197 | BUG_ON(!split || !split2); | 197 | BUG_ON(!split || !split2); |
198 | 198 | ||
199 | write_lock(&em_tree->lock); | 199 | write_lock(&em_tree->lock); |
@@ -377,7 +377,7 @@ next_slot: | |||
377 | 377 | ||
378 | search_start = max(key.offset, start); | 378 | search_start = max(key.offset, start); |
379 | if (recow) { | 379 | if (recow) { |
380 | btrfs_release_path(root, path); | 380 | btrfs_release_path(path); |
381 | continue; | 381 | continue; |
382 | } | 382 | } |
383 | 383 | ||
@@ -394,7 +394,7 @@ next_slot: | |||
394 | ret = btrfs_duplicate_item(trans, root, path, | 394 | ret = btrfs_duplicate_item(trans, root, path, |
395 | &new_key); | 395 | &new_key); |
396 | if (ret == -EAGAIN) { | 396 | if (ret == -EAGAIN) { |
397 | btrfs_release_path(root, path); | 397 | btrfs_release_path(path); |
398 | continue; | 398 | continue; |
399 | } | 399 | } |
400 | if (ret < 0) | 400 | if (ret < 0) |
@@ -517,7 +517,7 @@ next_slot: | |||
517 | del_nr = 0; | 517 | del_nr = 0; |
518 | del_slot = 0; | 518 | del_slot = 0; |
519 | 519 | ||
520 | btrfs_release_path(root, path); | 520 | btrfs_release_path(path); |
521 | continue; | 521 | continue; |
522 | } | 522 | } |
523 | 523 | ||
@@ -682,7 +682,7 @@ again: | |||
682 | new_key.offset = split; | 682 | new_key.offset = split; |
683 | ret = btrfs_duplicate_item(trans, root, path, &new_key); | 683 | ret = btrfs_duplicate_item(trans, root, path, &new_key); |
684 | if (ret == -EAGAIN) { | 684 | if (ret == -EAGAIN) { |
685 | btrfs_release_path(root, path); | 685 | btrfs_release_path(path); |
686 | goto again; | 686 | goto again; |
687 | } | 687 | } |
688 | BUG_ON(ret < 0); | 688 | BUG_ON(ret < 0); |
@@ -722,7 +722,7 @@ again: | |||
722 | ino, bytenr, orig_offset, | 722 | ino, bytenr, orig_offset, |
723 | &other_start, &other_end)) { | 723 | &other_start, &other_end)) { |
724 | if (recow) { | 724 | if (recow) { |
725 | btrfs_release_path(root, path); | 725 | btrfs_release_path(path); |
726 | goto again; | 726 | goto again; |
727 | } | 727 | } |
728 | extent_end = other_end; | 728 | extent_end = other_end; |
@@ -739,7 +739,7 @@ again: | |||
739 | ino, bytenr, orig_offset, | 739 | ino, bytenr, orig_offset, |
740 | &other_start, &other_end)) { | 740 | &other_start, &other_end)) { |
741 | if (recow) { | 741 | if (recow) { |
742 | btrfs_release_path(root, path); | 742 | btrfs_release_path(path); |
743 | goto again; | 743 | goto again; |
744 | } | 744 | } |
745 | key.offset = other_start; | 745 | key.offset = other_start; |
@@ -1376,7 +1376,7 @@ static long btrfs_fallocate(struct file *file, int mode, | |||
1376 | while (1) { | 1376 | while (1) { |
1377 | em = btrfs_get_extent(inode, NULL, 0, cur_offset, | 1377 | em = btrfs_get_extent(inode, NULL, 0, cur_offset, |
1378 | alloc_end - cur_offset, 0); | 1378 | alloc_end - cur_offset, 0); |
1379 | BUG_ON(IS_ERR(em) || !em); | 1379 | BUG_ON(IS_ERR_OR_NULL(em)); |
1380 | last_byte = min(extent_map_end(em), alloc_end); | 1380 | last_byte = min(extent_map_end(em), alloc_end); |
1381 | last_byte = (last_byte + mask) & ~mask; | 1381 | last_byte = (last_byte + mask) & ~mask; |
1382 | if (em->block_start == EXTENT_MAP_HOLE || | 1382 | if (em->block_start == EXTENT_MAP_HOLE || |
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 25a13ab750f8..70d45795d758 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -53,7 +53,7 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root, | |||
53 | if (ret < 0) | 53 | if (ret < 0) |
54 | return ERR_PTR(ret); | 54 | return ERR_PTR(ret); |
55 | if (ret > 0) { | 55 | if (ret > 0) { |
56 | btrfs_release_path(root, path); | 56 | btrfs_release_path(path); |
57 | return ERR_PTR(-ENOENT); | 57 | return ERR_PTR(-ENOENT); |
58 | } | 58 | } |
59 | 59 | ||
@@ -62,7 +62,7 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root, | |||
62 | struct btrfs_free_space_header); | 62 | struct btrfs_free_space_header); |
63 | btrfs_free_space_key(leaf, header, &disk_key); | 63 | btrfs_free_space_key(leaf, header, &disk_key); |
64 | btrfs_disk_key_to_cpu(&location, &disk_key); | 64 | btrfs_disk_key_to_cpu(&location, &disk_key); |
65 | btrfs_release_path(root, path); | 65 | btrfs_release_path(path); |
66 | 66 | ||
67 | inode = btrfs_iget(root->fs_info->sb, &location, root, NULL); | 67 | inode = btrfs_iget(root->fs_info->sb, &location, root, NULL); |
68 | if (!inode) | 68 | if (!inode) |
@@ -140,7 +140,7 @@ int __create_free_space_inode(struct btrfs_root *root, | |||
140 | btrfs_set_inode_transid(leaf, inode_item, trans->transid); | 140 | btrfs_set_inode_transid(leaf, inode_item, trans->transid); |
141 | btrfs_set_inode_block_group(leaf, inode_item, offset); | 141 | btrfs_set_inode_block_group(leaf, inode_item, offset); |
142 | btrfs_mark_buffer_dirty(leaf); | 142 | btrfs_mark_buffer_dirty(leaf); |
143 | btrfs_release_path(root, path); | 143 | btrfs_release_path(path); |
144 | 144 | ||
145 | key.objectid = BTRFS_FREE_SPACE_OBJECTID; | 145 | key.objectid = BTRFS_FREE_SPACE_OBJECTID; |
146 | key.offset = offset; | 146 | key.offset = offset; |
@@ -149,7 +149,7 @@ int __create_free_space_inode(struct btrfs_root *root, | |||
149 | ret = btrfs_insert_empty_item(trans, root, path, &key, | 149 | ret = btrfs_insert_empty_item(trans, root, path, &key, |
150 | sizeof(struct btrfs_free_space_header)); | 150 | sizeof(struct btrfs_free_space_header)); |
151 | if (ret < 0) { | 151 | if (ret < 0) { |
152 | btrfs_release_path(root, path); | 152 | btrfs_release_path(path); |
153 | return ret; | 153 | return ret; |
154 | } | 154 | } |
155 | leaf = path->nodes[0]; | 155 | leaf = path->nodes[0]; |
@@ -158,7 +158,7 @@ int __create_free_space_inode(struct btrfs_root *root, | |||
158 | memset_extent_buffer(leaf, 0, (unsigned long)header, sizeof(*header)); | 158 | memset_extent_buffer(leaf, 0, (unsigned long)header, sizeof(*header)); |
159 | btrfs_set_free_space_key(leaf, header, &disk_key); | 159 | btrfs_set_free_space_key(leaf, header, &disk_key); |
160 | btrfs_mark_buffer_dirty(leaf); | 160 | btrfs_mark_buffer_dirty(leaf); |
161 | btrfs_release_path(root, path); | 161 | btrfs_release_path(path); |
162 | 162 | ||
163 | return 0; | 163 | return 0; |
164 | } | 164 | } |
@@ -266,7 +266,7 @@ int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, | |||
266 | if (ret < 0) | 266 | if (ret < 0) |
267 | goto out; | 267 | goto out; |
268 | else if (ret > 0) { | 268 | else if (ret > 0) { |
269 | btrfs_release_path(root, path); | 269 | btrfs_release_path(path); |
270 | ret = 0; | 270 | ret = 0; |
271 | goto out; | 271 | goto out; |
272 | } | 272 | } |
@@ -279,7 +279,7 @@ int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, | |||
279 | num_entries = btrfs_free_space_entries(leaf, header); | 279 | num_entries = btrfs_free_space_entries(leaf, header); |
280 | num_bitmaps = btrfs_free_space_bitmaps(leaf, header); | 280 | num_bitmaps = btrfs_free_space_bitmaps(leaf, header); |
281 | generation = btrfs_free_space_generation(leaf, header); | 281 | generation = btrfs_free_space_generation(leaf, header); |
282 | btrfs_release_path(root, path); | 282 | btrfs_release_path(path); |
283 | 283 | ||
284 | if (BTRFS_I(inode)->generation != generation) { | 284 | if (BTRFS_I(inode)->generation != generation) { |
285 | printk(KERN_ERR "btrfs: free space inode generation (%llu) did" | 285 | printk(KERN_ERR "btrfs: free space inode generation (%llu) did" |
@@ -842,7 +842,7 @@ int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, | |||
842 | EXTENT_DIRTY | EXTENT_DELALLOC | | 842 | EXTENT_DIRTY | EXTENT_DELALLOC | |
843 | EXTENT_DO_ACCOUNTING, 0, 0, NULL, | 843 | EXTENT_DO_ACCOUNTING, 0, 0, NULL, |
844 | GFP_NOFS); | 844 | GFP_NOFS); |
845 | btrfs_release_path(root, path); | 845 | btrfs_release_path(path); |
846 | goto out_free; | 846 | goto out_free; |
847 | } | 847 | } |
848 | } | 848 | } |
@@ -852,7 +852,7 @@ int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, | |||
852 | btrfs_set_free_space_bitmaps(leaf, header, bitmaps); | 852 | btrfs_set_free_space_bitmaps(leaf, header, bitmaps); |
853 | btrfs_set_free_space_generation(leaf, header, trans->transid); | 853 | btrfs_set_free_space_generation(leaf, header, trans->transid); |
854 | btrfs_mark_buffer_dirty(leaf); | 854 | btrfs_mark_buffer_dirty(leaf); |
855 | btrfs_release_path(root, path); | 855 | btrfs_release_path(path); |
856 | 856 | ||
857 | ret = 1; | 857 | ret = 1; |
858 | 858 | ||
@@ -1504,7 +1504,7 @@ out: | |||
1504 | return ret; | 1504 | return ret; |
1505 | } | 1505 | } |
1506 | 1506 | ||
1507 | bool try_merge_free_space(struct btrfs_free_space_ctl *ctl, | 1507 | static bool try_merge_free_space(struct btrfs_free_space_ctl *ctl, |
1508 | struct btrfs_free_space *info, bool update_stat) | 1508 | struct btrfs_free_space *info, bool update_stat) |
1509 | { | 1509 | { |
1510 | struct btrfs_free_space *left_info; | 1510 | struct btrfs_free_space *left_info; |
@@ -1984,8 +1984,6 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group, | |||
1984 | while(1) { | 1984 | while(1) { |
1985 | if (entry->bytes < bytes || | 1985 | if (entry->bytes < bytes || |
1986 | (!entry->bitmap && entry->offset < min_start)) { | 1986 | (!entry->bitmap && entry->offset < min_start)) { |
1987 | struct rb_node *node; | ||
1988 | |||
1989 | node = rb_next(&entry->offset_index); | 1987 | node = rb_next(&entry->offset_index); |
1990 | if (!node) | 1988 | if (!node) |
1991 | break; | 1989 | break; |
@@ -1999,7 +1997,6 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group, | |||
1999 | cluster, entry, bytes, | 1997 | cluster, entry, bytes, |
2000 | min_start); | 1998 | min_start); |
2001 | if (ret == 0) { | 1999 | if (ret == 0) { |
2002 | struct rb_node *node; | ||
2003 | node = rb_next(&entry->offset_index); | 2000 | node = rb_next(&entry->offset_index); |
2004 | if (!node) | 2001 | if (!node) |
2005 | break; | 2002 | break; |
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c index 7967e85c72f5..000970512624 100644 --- a/fs/btrfs/inode-map.c +++ b/fs/btrfs/inode-map.c | |||
@@ -86,7 +86,7 @@ again: | |||
86 | * in the next search. | 86 | * in the next search. |
87 | */ | 87 | */ |
88 | btrfs_item_key_to_cpu(leaf, &key, 0); | 88 | btrfs_item_key_to_cpu(leaf, &key, 0); |
89 | btrfs_release_path(root, path); | 89 | btrfs_release_path(path); |
90 | root->cache_progress = last; | 90 | root->cache_progress = last; |
91 | mutex_unlock(&root->fs_commit_mutex); | 91 | mutex_unlock(&root->fs_commit_mutex); |
92 | schedule_timeout(1); | 92 | schedule_timeout(1); |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 6cef48572e9e..8ae72c3eedb1 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/posix_acl.h> | 37 | #include <linux/posix_acl.h> |
38 | #include <linux/falloc.h> | 38 | #include <linux/falloc.h> |
39 | #include <linux/slab.h> | 39 | #include <linux/slab.h> |
40 | #include <linux/ratelimit.h> | ||
40 | #include "compat.h" | 41 | #include "compat.h" |
41 | #include "ctree.h" | 42 | #include "ctree.h" |
42 | #include "disk-io.h" | 43 | #include "disk-io.h" |
@@ -650,7 +651,7 @@ retry: | |||
650 | async_extent->start + | 651 | async_extent->start + |
651 | async_extent->ram_size - 1, 0); | 652 | async_extent->ram_size - 1, 0); |
652 | 653 | ||
653 | em = alloc_extent_map(GFP_NOFS); | 654 | em = alloc_extent_map(); |
654 | BUG_ON(!em); | 655 | BUG_ON(!em); |
655 | em->start = async_extent->start; | 656 | em->start = async_extent->start; |
656 | em->len = async_extent->ram_size; | 657 | em->len = async_extent->ram_size; |
@@ -836,7 +837,7 @@ static noinline int cow_file_range(struct inode *inode, | |||
836 | (u64)-1, &ins, 1); | 837 | (u64)-1, &ins, 1); |
837 | BUG_ON(ret); | 838 | BUG_ON(ret); |
838 | 839 | ||
839 | em = alloc_extent_map(GFP_NOFS); | 840 | em = alloc_extent_map(); |
840 | BUG_ON(!em); | 841 | BUG_ON(!em); |
841 | em->start = start; | 842 | em->start = start; |
842 | em->orig_start = em->start; | 843 | em->orig_start = em->start; |
@@ -1176,7 +1177,7 @@ out_check: | |||
1176 | goto next_slot; | 1177 | goto next_slot; |
1177 | } | 1178 | } |
1178 | 1179 | ||
1179 | btrfs_release_path(root, path); | 1180 | btrfs_release_path(path); |
1180 | if (cow_start != (u64)-1) { | 1181 | if (cow_start != (u64)-1) { |
1181 | ret = cow_file_range(inode, locked_page, cow_start, | 1182 | ret = cow_file_range(inode, locked_page, cow_start, |
1182 | found_key.offset - 1, page_started, | 1183 | found_key.offset - 1, page_started, |
@@ -1189,7 +1190,7 @@ out_check: | |||
1189 | struct extent_map *em; | 1190 | struct extent_map *em; |
1190 | struct extent_map_tree *em_tree; | 1191 | struct extent_map_tree *em_tree; |
1191 | em_tree = &BTRFS_I(inode)->extent_tree; | 1192 | em_tree = &BTRFS_I(inode)->extent_tree; |
1192 | em = alloc_extent_map(GFP_NOFS); | 1193 | em = alloc_extent_map(); |
1193 | BUG_ON(!em); | 1194 | BUG_ON(!em); |
1194 | em->start = cur_offset; | 1195 | em->start = cur_offset; |
1195 | em->orig_start = em->start; | 1196 | em->orig_start = em->start; |
@@ -1234,7 +1235,7 @@ out_check: | |||
1234 | if (cur_offset > end) | 1235 | if (cur_offset > end) |
1235 | break; | 1236 | break; |
1236 | } | 1237 | } |
1237 | btrfs_release_path(root, path); | 1238 | btrfs_release_path(path); |
1238 | 1239 | ||
1239 | if (cur_offset <= end && cow_start == (u64)-1) | 1240 | if (cur_offset <= end && cow_start == (u64)-1) |
1240 | cow_start = cur_offset; | 1241 | cow_start = cur_offset; |
@@ -1865,7 +1866,7 @@ static int btrfs_io_failed_hook(struct bio *failed_bio, | |||
1865 | } | 1866 | } |
1866 | read_unlock(&em_tree->lock); | 1867 | read_unlock(&em_tree->lock); |
1867 | 1868 | ||
1868 | if (!em || IS_ERR(em)) { | 1869 | if (IS_ERR_OR_NULL(em)) { |
1869 | kfree(failrec); | 1870 | kfree(failrec); |
1870 | return -EIO; | 1871 | return -EIO; |
1871 | } | 1872 | } |
@@ -2014,13 +2015,11 @@ good: | |||
2014 | return 0; | 2015 | return 0; |
2015 | 2016 | ||
2016 | zeroit: | 2017 | zeroit: |
2017 | if (printk_ratelimit()) { | 2018 | printk_ratelimited(KERN_INFO "btrfs csum failed ino %llu off %llu csum %u " |
2018 | printk(KERN_INFO "btrfs csum failed ino %llu off %llu csum %u " | ||
2019 | "private %llu\n", | 2019 | "private %llu\n", |
2020 | (unsigned long long)btrfs_ino(page->mapping->host), | 2020 | (unsigned long long)btrfs_ino(page->mapping->host), |
2021 | (unsigned long long)start, csum, | 2021 | (unsigned long long)start, csum, |
2022 | (unsigned long long)private); | 2022 | (unsigned long long)private); |
2023 | } | ||
2024 | memset(kaddr + offset, 1, end - start + 1); | 2023 | memset(kaddr + offset, 1, end - start + 1); |
2025 | flush_dcache_page(page); | 2024 | flush_dcache_page(page); |
2026 | kunmap_atomic(kaddr, KM_USER0); | 2025 | kunmap_atomic(kaddr, KM_USER0); |
@@ -2357,7 +2356,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) | |||
2357 | break; | 2356 | break; |
2358 | 2357 | ||
2359 | /* release the path since we're done with it */ | 2358 | /* release the path since we're done with it */ |
2360 | btrfs_release_path(root, path); | 2359 | btrfs_release_path(path); |
2361 | 2360 | ||
2362 | /* | 2361 | /* |
2363 | * this is where we are basically btrfs_lookup, without the | 2362 | * this is where we are basically btrfs_lookup, without the |
@@ -2740,7 +2739,7 @@ static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans, | |||
2740 | ret = btrfs_delete_one_dir_name(trans, root, path, di); | 2739 | ret = btrfs_delete_one_dir_name(trans, root, path, di); |
2741 | if (ret) | 2740 | if (ret) |
2742 | goto err; | 2741 | goto err; |
2743 | btrfs_release_path(root, path); | 2742 | btrfs_release_path(path); |
2744 | 2743 | ||
2745 | ret = btrfs_del_inode_ref(trans, root, name, name_len, ino, | 2744 | ret = btrfs_del_inode_ref(trans, root, name, name_len, ino, |
2746 | dir_ino, &index); | 2745 | dir_ino, &index); |
@@ -2882,7 +2881,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, | |||
2882 | } else { | 2881 | } else { |
2883 | check_link = 0; | 2882 | check_link = 0; |
2884 | } | 2883 | } |
2885 | btrfs_release_path(root, path); | 2884 | btrfs_release_path(path); |
2886 | 2885 | ||
2887 | ret = btrfs_lookup_inode(trans, root, path, | 2886 | ret = btrfs_lookup_inode(trans, root, path, |
2888 | &BTRFS_I(inode)->location, 0); | 2887 | &BTRFS_I(inode)->location, 0); |
@@ -2896,7 +2895,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, | |||
2896 | } else { | 2895 | } else { |
2897 | check_link = 0; | 2896 | check_link = 0; |
2898 | } | 2897 | } |
2899 | btrfs_release_path(root, path); | 2898 | btrfs_release_path(path); |
2900 | 2899 | ||
2901 | if (ret == 0 && S_ISREG(inode->i_mode)) { | 2900 | if (ret == 0 && S_ISREG(inode->i_mode)) { |
2902 | ret = btrfs_lookup_file_extent(trans, root, path, | 2901 | ret = btrfs_lookup_file_extent(trans, root, path, |
@@ -2908,7 +2907,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, | |||
2908 | BUG_ON(ret == 0); | 2907 | BUG_ON(ret == 0); |
2909 | if (check_path_shared(root, path)) | 2908 | if (check_path_shared(root, path)) |
2910 | goto out; | 2909 | goto out; |
2911 | btrfs_release_path(root, path); | 2910 | btrfs_release_path(path); |
2912 | } | 2911 | } |
2913 | 2912 | ||
2914 | if (!check_link) { | 2913 | if (!check_link) { |
@@ -2929,7 +2928,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, | |||
2929 | err = 0; | 2928 | err = 0; |
2930 | goto out; | 2929 | goto out; |
2931 | } | 2930 | } |
2932 | btrfs_release_path(root, path); | 2931 | btrfs_release_path(path); |
2933 | 2932 | ||
2934 | ref = btrfs_lookup_inode_ref(trans, root, path, | 2933 | ref = btrfs_lookup_inode_ref(trans, root, path, |
2935 | dentry->d_name.name, dentry->d_name.len, | 2934 | dentry->d_name.name, dentry->d_name.len, |
@@ -2942,7 +2941,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, | |||
2942 | if (check_path_shared(root, path)) | 2941 | if (check_path_shared(root, path)) |
2943 | goto out; | 2942 | goto out; |
2944 | index = btrfs_inode_ref_index(path->nodes[0], ref); | 2943 | index = btrfs_inode_ref_index(path->nodes[0], ref); |
2945 | btrfs_release_path(root, path); | 2944 | btrfs_release_path(path); |
2946 | 2945 | ||
2947 | /* | 2946 | /* |
2948 | * This is a commit root search, if we can lookup inode item and other | 2947 | * This is a commit root search, if we can lookup inode item and other |
@@ -3035,14 +3034,14 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, | |||
3035 | 3034 | ||
3036 | di = btrfs_lookup_dir_item(trans, root, path, dir_ino, | 3035 | di = btrfs_lookup_dir_item(trans, root, path, dir_ino, |
3037 | name, name_len, -1); | 3036 | name, name_len, -1); |
3038 | BUG_ON(!di || IS_ERR(di)); | 3037 | BUG_ON(IS_ERR_OR_NULL(di)); |
3039 | 3038 | ||
3040 | leaf = path->nodes[0]; | 3039 | leaf = path->nodes[0]; |
3041 | btrfs_dir_item_key_to_cpu(leaf, di, &key); | 3040 | btrfs_dir_item_key_to_cpu(leaf, di, &key); |
3042 | WARN_ON(key.type != BTRFS_ROOT_ITEM_KEY || key.objectid != objectid); | 3041 | WARN_ON(key.type != BTRFS_ROOT_ITEM_KEY || key.objectid != objectid); |
3043 | ret = btrfs_delete_one_dir_name(trans, root, path, di); | 3042 | ret = btrfs_delete_one_dir_name(trans, root, path, di); |
3044 | BUG_ON(ret); | 3043 | BUG_ON(ret); |
3045 | btrfs_release_path(root, path); | 3044 | btrfs_release_path(path); |
3046 | 3045 | ||
3047 | ret = btrfs_del_root_ref(trans, root->fs_info->tree_root, | 3046 | ret = btrfs_del_root_ref(trans, root->fs_info->tree_root, |
3048 | objectid, root->root_key.objectid, | 3047 | objectid, root->root_key.objectid, |
@@ -3051,14 +3050,14 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, | |||
3051 | BUG_ON(ret != -ENOENT); | 3050 | BUG_ON(ret != -ENOENT); |
3052 | di = btrfs_search_dir_index_item(root, path, dir_ino, | 3051 | di = btrfs_search_dir_index_item(root, path, dir_ino, |
3053 | name, name_len); | 3052 | name, name_len); |
3054 | BUG_ON(!di || IS_ERR(di)); | 3053 | BUG_ON(IS_ERR_OR_NULL(di)); |
3055 | 3054 | ||
3056 | leaf = path->nodes[0]; | 3055 | leaf = path->nodes[0]; |
3057 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); | 3056 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); |
3058 | btrfs_release_path(root, path); | 3057 | btrfs_release_path(path); |
3059 | index = key.offset; | 3058 | index = key.offset; |
3060 | } | 3059 | } |
3061 | btrfs_release_path(root, path); | 3060 | btrfs_release_path(path); |
3062 | 3061 | ||
3063 | ret = btrfs_delete_delayed_dir_index(trans, root, dir, index); | 3062 | ret = btrfs_delete_delayed_dir_index(trans, root, dir, index); |
3064 | BUG_ON(ret); | 3063 | BUG_ON(ret); |
@@ -3114,178 +3113,6 @@ out: | |||
3114 | return err; | 3113 | return err; |
3115 | } | 3114 | } |
3116 | 3115 | ||
3117 | #if 0 | ||
3118 | /* | ||
3119 | * when truncating bytes in a file, it is possible to avoid reading | ||
3120 | * the leaves that contain only checksum items. This can be the | ||
3121 | * majority of the IO required to delete a large file, but it must | ||
3122 | * be done carefully. | ||
3123 | * | ||
3124 | * The keys in the level just above the leaves are checked to make sure | ||
3125 | * the lowest key in a given leaf is a csum key, and starts at an offset | ||
3126 | * after the new size. | ||
3127 | * | ||
3128 | * Then the key for the next leaf is checked to make sure it also has | ||
3129 | * a checksum item for the same file. If it does, we know our target leaf | ||
3130 | * contains only checksum items, and it can be safely freed without reading | ||
3131 | * it. | ||
3132 | * | ||
3133 | * This is just an optimization targeted at large files. It may do | ||
3134 | * nothing. It will return 0 unless things went badly. | ||
3135 | */ | ||
3136 | static noinline int drop_csum_leaves(struct btrfs_trans_handle *trans, | ||
3137 | struct btrfs_root *root, | ||
3138 | struct btrfs_path *path, | ||
3139 | struct inode *inode, u64 new_size) | ||
3140 | { | ||
3141 | struct btrfs_key key; | ||
3142 | int ret; | ||
3143 | int nritems; | ||
3144 | struct btrfs_key found_key; | ||
3145 | struct btrfs_key other_key; | ||
3146 | struct btrfs_leaf_ref *ref; | ||
3147 | u64 leaf_gen; | ||
3148 | u64 leaf_start; | ||
3149 | |||
3150 | path->lowest_level = 1; | ||
3151 | key.objectid = inode->i_ino; | ||
3152 | key.type = BTRFS_CSUM_ITEM_KEY; | ||
3153 | key.offset = new_size; | ||
3154 | again: | ||
3155 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); | ||
3156 | if (ret < 0) | ||
3157 | goto out; | ||
3158 | |||
3159 | if (path->nodes[1] == NULL) { | ||
3160 | ret = 0; | ||
3161 | goto out; | ||
3162 | } | ||
3163 | ret = 0; | ||
3164 | btrfs_node_key_to_cpu(path->nodes[1], &found_key, path->slots[1]); | ||
3165 | nritems = btrfs_header_nritems(path->nodes[1]); | ||
3166 | |||
3167 | if (!nritems) | ||
3168 | goto out; | ||
3169 | |||
3170 | if (path->slots[1] >= nritems) | ||
3171 | goto next_node; | ||
3172 | |||
3173 | /* did we find a key greater than anything we want to delete? */ | ||
3174 | if (found_key.objectid > inode->i_ino || | ||
3175 | (found_key.objectid == inode->i_ino && found_key.type > key.type)) | ||
3176 | goto out; | ||
3177 | |||
3178 | /* we check the next key in the node to make sure the leave contains | ||
3179 | * only checksum items. This comparison doesn't work if our | ||
3180 | * leaf is the last one in the node | ||
3181 | */ | ||
3182 | if (path->slots[1] + 1 >= nritems) { | ||
3183 | next_node: | ||
3184 | /* search forward from the last key in the node, this | ||
3185 | * will bring us into the next node in the tree | ||
3186 | */ | ||
3187 | btrfs_node_key_to_cpu(path->nodes[1], &found_key, nritems - 1); | ||
3188 | |||
3189 | /* unlikely, but we inc below, so check to be safe */ | ||
3190 | if (found_key.offset == (u64)-1) | ||
3191 | goto out; | ||
3192 | |||
3193 | /* search_forward needs a path with locks held, do the | ||
3194 | * search again for the original key. It is possible | ||
3195 | * this will race with a balance and return a path that | ||
3196 | * we could modify, but this drop is just an optimization | ||
3197 | * and is allowed to miss some leaves. | ||
3198 | */ | ||
3199 | btrfs_release_path(root, path); | ||
3200 | found_key.offset++; | ||
3201 | |||
3202 | /* setup a max key for search_forward */ | ||
3203 | other_key.offset = (u64)-1; | ||
3204 | other_key.type = key.type; | ||
3205 | other_key.objectid = key.objectid; | ||
3206 | |||
3207 | path->keep_locks = 1; | ||
3208 | ret = btrfs_search_forward(root, &found_key, &other_key, | ||
3209 | path, 0, 0); | ||
3210 | path->keep_locks = 0; | ||
3211 | if (ret || found_key.objectid != key.objectid || | ||
3212 | found_key.type != key.type) { | ||
3213 | ret = 0; | ||
3214 | goto out; | ||
3215 | } | ||
3216 | |||
3217 | key.offset = found_key.offset; | ||
3218 | btrfs_release_path(root, path); | ||
3219 | cond_resched(); | ||
3220 | goto again; | ||
3221 | } | ||
3222 | |||
3223 | /* we know there's one more slot after us in the tree, | ||
3224 | * read that key so we can verify it is also a checksum item | ||
3225 | */ | ||
3226 | btrfs_node_key_to_cpu(path->nodes[1], &other_key, path->slots[1] + 1); | ||
3227 | |||
3228 | if (found_key.objectid < inode->i_ino) | ||
3229 | goto next_key; | ||
3230 | |||
3231 | if (found_key.type != key.type || found_key.offset < new_size) | ||
3232 | goto next_key; | ||
3233 | |||
3234 | /* | ||
3235 | * if the key for the next leaf isn't a csum key from this objectid, | ||
3236 | * we can't be sure there aren't good items inside this leaf. | ||
3237 | * Bail out | ||
3238 | */ | ||
3239 | if (other_key.objectid != inode->i_ino || other_key.type != key.type) | ||
3240 | goto out; | ||
3241 | |||
3242 | leaf_start = btrfs_node_blockptr(path->nodes[1], path->slots[1]); | ||
3243 | leaf_gen = btrfs_node_ptr_generation(path->nodes[1], path->slots[1]); | ||
3244 | /* | ||
3245 | * it is safe to delete this leaf, it contains only | ||
3246 | * csum items from this inode at an offset >= new_size | ||
3247 | */ | ||
3248 | ret = btrfs_del_leaf(trans, root, path, leaf_start); | ||
3249 | BUG_ON(ret); | ||
3250 | |||
3251 | if (root->ref_cows && leaf_gen < trans->transid) { | ||
3252 | ref = btrfs_alloc_leaf_ref(root, 0); | ||
3253 | if (ref) { | ||
3254 | ref->root_gen = root->root_key.offset; | ||
3255 | ref->bytenr = leaf_start; | ||
3256 | ref->owner = 0; | ||
3257 | ref->generation = leaf_gen; | ||
3258 | ref->nritems = 0; | ||
3259 | |||
3260 | btrfs_sort_leaf_ref(ref); | ||
3261 | |||
3262 | ret = btrfs_add_leaf_ref(root, ref, 0); | ||
3263 | WARN_ON(ret); | ||
3264 | btrfs_free_leaf_ref(root, ref); | ||
3265 | } else { | ||
3266 | WARN_ON(1); | ||
3267 | } | ||
3268 | } | ||
3269 | next_key: | ||
3270 | btrfs_release_path(root, path); | ||
3271 | |||
3272 | if (other_key.objectid == inode->i_ino && | ||
3273 | other_key.type == key.type && other_key.offset > key.offset) { | ||
3274 | key.offset = other_key.offset; | ||
3275 | cond_resched(); | ||
3276 | goto again; | ||
3277 | } | ||
3278 | ret = 0; | ||
3279 | out: | ||
3280 | /* fixup any changes we've made to the path */ | ||
3281 | path->lowest_level = 0; | ||
3282 | path->keep_locks = 0; | ||
3283 | btrfs_release_path(root, path); | ||
3284 | return ret; | ||
3285 | } | ||
3286 | |||
3287 | #endif | ||
3288 | |||
3289 | /* | 3116 | /* |
3290 | * this can truncate away extent items, csum items and directory items. | 3117 | * this can truncate away extent items, csum items and directory items. |
3291 | * It starts at a high offset and removes keys until it can't find | 3118 | * It starts at a high offset and removes keys until it can't find |
@@ -3510,7 +3337,7 @@ delete: | |||
3510 | BUG_ON(ret); | 3337 | BUG_ON(ret); |
3511 | pending_del_nr = 0; | 3338 | pending_del_nr = 0; |
3512 | } | 3339 | } |
3513 | btrfs_release_path(root, path); | 3340 | btrfs_release_path(path); |
3514 | goto search_again; | 3341 | goto search_again; |
3515 | } else { | 3342 | } else { |
3516 | path->slots[0]--; | 3343 | path->slots[0]--; |
@@ -3668,7 +3495,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) | |||
3668 | while (1) { | 3495 | while (1) { |
3669 | em = btrfs_get_extent(inode, NULL, 0, cur_offset, | 3496 | em = btrfs_get_extent(inode, NULL, 0, cur_offset, |
3670 | block_end - cur_offset, 0); | 3497 | block_end - cur_offset, 0); |
3671 | BUG_ON(IS_ERR(em) || !em); | 3498 | BUG_ON(IS_ERR_OR_NULL(em)); |
3672 | last_byte = min(extent_map_end(em), block_end); | 3499 | last_byte = min(extent_map_end(em), block_end); |
3673 | last_byte = (last_byte + mask) & ~mask; | 3500 | last_byte = (last_byte + mask) & ~mask; |
3674 | if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) { | 3501 | if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) { |
@@ -3878,7 +3705,7 @@ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry, | |||
3878 | if (IS_ERR(di)) | 3705 | if (IS_ERR(di)) |
3879 | ret = PTR_ERR(di); | 3706 | ret = PTR_ERR(di); |
3880 | 3707 | ||
3881 | if (!di || IS_ERR(di)) | 3708 | if (IS_ERR_OR_NULL(di)) |
3882 | goto out_err; | 3709 | goto out_err; |
3883 | 3710 | ||
3884 | btrfs_dir_item_key_to_cpu(path->nodes[0], di, location); | 3711 | btrfs_dir_item_key_to_cpu(path->nodes[0], di, location); |
@@ -3936,7 +3763,7 @@ static int fixup_tree_root_location(struct btrfs_root *root, | |||
3936 | if (ret) | 3763 | if (ret) |
3937 | goto out; | 3764 | goto out; |
3938 | 3765 | ||
3939 | btrfs_release_path(root->fs_info->tree_root, path); | 3766 | btrfs_release_path(path); |
3940 | 3767 | ||
3941 | new_root = btrfs_read_fs_root_no_name(root->fs_info, location); | 3768 | new_root = btrfs_read_fs_root_no_name(root->fs_info, location); |
3942 | if (IS_ERR(new_root)) { | 3769 | if (IS_ERR(new_root)) { |
@@ -4479,24 +4306,20 @@ void btrfs_dirty_inode(struct inode *inode) | |||
4479 | btrfs_end_transaction(trans, root); | 4306 | btrfs_end_transaction(trans, root); |
4480 | trans = btrfs_start_transaction(root, 1); | 4307 | trans = btrfs_start_transaction(root, 1); |
4481 | if (IS_ERR(trans)) { | 4308 | if (IS_ERR(trans)) { |
4482 | if (printk_ratelimit()) { | 4309 | printk_ratelimited(KERN_ERR "btrfs: fail to " |
4483 | printk(KERN_ERR "btrfs: fail to " | ||
4484 | "dirty inode %llu error %ld\n", | 4310 | "dirty inode %llu error %ld\n", |
4485 | (unsigned long long)btrfs_ino(inode), | 4311 | (unsigned long long)btrfs_ino(inode), |
4486 | PTR_ERR(trans)); | 4312 | PTR_ERR(trans)); |
4487 | } | ||
4488 | return; | 4313 | return; |
4489 | } | 4314 | } |
4490 | btrfs_set_trans_block_group(trans, inode); | 4315 | btrfs_set_trans_block_group(trans, inode); |
4491 | 4316 | ||
4492 | ret = btrfs_update_inode(trans, root, inode); | 4317 | ret = btrfs_update_inode(trans, root, inode); |
4493 | if (ret) { | 4318 | if (ret) { |
4494 | if (printk_ratelimit()) { | 4319 | printk_ratelimited(KERN_ERR "btrfs: fail to " |
4495 | printk(KERN_ERR "btrfs: fail to " | ||
4496 | "dirty inode %llu error %d\n", | 4320 | "dirty inode %llu error %d\n", |
4497 | (unsigned long long)btrfs_ino(inode), | 4321 | (unsigned long long)btrfs_ino(inode), |
4498 | ret); | 4322 | ret); |
4499 | } | ||
4500 | } | 4323 | } |
4501 | } | 4324 | } |
4502 | btrfs_end_transaction(trans, root); | 4325 | btrfs_end_transaction(trans, root); |
@@ -5146,7 +4969,7 @@ again: | |||
5146 | else | 4969 | else |
5147 | goto out; | 4970 | goto out; |
5148 | } | 4971 | } |
5149 | em = alloc_extent_map(GFP_NOFS); | 4972 | em = alloc_extent_map(); |
5150 | if (!em) { | 4973 | if (!em) { |
5151 | err = -ENOMEM; | 4974 | err = -ENOMEM; |
5152 | goto out; | 4975 | goto out; |
@@ -5300,7 +5123,7 @@ again: | |||
5300 | kunmap(page); | 5123 | kunmap(page); |
5301 | free_extent_map(em); | 5124 | free_extent_map(em); |
5302 | em = NULL; | 5125 | em = NULL; |
5303 | btrfs_release_path(root, path); | 5126 | btrfs_release_path(path); |
5304 | trans = btrfs_join_transaction(root, 1); | 5127 | trans = btrfs_join_transaction(root, 1); |
5305 | if (IS_ERR(trans)) | 5128 | if (IS_ERR(trans)) |
5306 | return ERR_CAST(trans); | 5129 | return ERR_CAST(trans); |
@@ -5326,7 +5149,7 @@ not_found_em: | |||
5326 | em->block_start = EXTENT_MAP_HOLE; | 5149 | em->block_start = EXTENT_MAP_HOLE; |
5327 | set_bit(EXTENT_FLAG_VACANCY, &em->flags); | 5150 | set_bit(EXTENT_FLAG_VACANCY, &em->flags); |
5328 | insert: | 5151 | insert: |
5329 | btrfs_release_path(root, path); | 5152 | btrfs_release_path(path); |
5330 | if (em->start > start || extent_map_end(em) <= start) { | 5153 | if (em->start > start || extent_map_end(em) <= start) { |
5331 | printk(KERN_ERR "Btrfs: bad extent! em: [%llu %llu] passed " | 5154 | printk(KERN_ERR "Btrfs: bad extent! em: [%llu %llu] passed " |
5332 | "[%llu %llu]\n", (unsigned long long)em->start, | 5155 | "[%llu %llu]\n", (unsigned long long)em->start, |
@@ -5459,7 +5282,7 @@ struct extent_map *btrfs_get_extent_fiemap(struct inode *inode, struct page *pag | |||
5459 | u64 hole_start = start; | 5282 | u64 hole_start = start; |
5460 | u64 hole_len = len; | 5283 | u64 hole_len = len; |
5461 | 5284 | ||
5462 | em = alloc_extent_map(GFP_NOFS); | 5285 | em = alloc_extent_map(); |
5463 | if (!em) { | 5286 | if (!em) { |
5464 | err = -ENOMEM; | 5287 | err = -ENOMEM; |
5465 | goto out; | 5288 | goto out; |
@@ -5560,7 +5383,7 @@ static struct extent_map *btrfs_new_extent_direct(struct inode *inode, | |||
5560 | } | 5383 | } |
5561 | 5384 | ||
5562 | if (!em) { | 5385 | if (!em) { |
5563 | em = alloc_extent_map(GFP_NOFS); | 5386 | em = alloc_extent_map(); |
5564 | if (!em) { | 5387 | if (!em) { |
5565 | em = ERR_PTR(-ENOMEM); | 5388 | em = ERR_PTR(-ENOMEM); |
5566 | goto out; | 5389 | goto out; |
@@ -6865,9 +6688,9 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
6865 | ei->delayed_node = NULL; | 6688 | ei->delayed_node = NULL; |
6866 | 6689 | ||
6867 | inode = &ei->vfs_inode; | 6690 | inode = &ei->vfs_inode; |
6868 | extent_map_tree_init(&ei->extent_tree, GFP_NOFS); | 6691 | extent_map_tree_init(&ei->extent_tree); |
6869 | extent_io_tree_init(&ei->io_tree, &inode->i_data, GFP_NOFS); | 6692 | extent_io_tree_init(&ei->io_tree, &inode->i_data); |
6870 | extent_io_tree_init(&ei->io_failure_tree, &inode->i_data, GFP_NOFS); | 6693 | extent_io_tree_init(&ei->io_failure_tree, &inode->i_data); |
6871 | mutex_init(&ei->log_mutex); | 6694 | mutex_init(&ei->log_mutex); |
6872 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); | 6695 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); |
6873 | INIT_LIST_HEAD(&ei->i_orphan); | 6696 | INIT_LIST_HEAD(&ei->i_orphan); |
@@ -7265,58 +7088,6 @@ int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput) | |||
7265 | return 0; | 7088 | return 0; |
7266 | } | 7089 | } |
7267 | 7090 | ||
7268 | int btrfs_start_one_delalloc_inode(struct btrfs_root *root, int delay_iput, | ||
7269 | int sync) | ||
7270 | { | ||
7271 | struct btrfs_inode *binode; | ||
7272 | struct inode *inode = NULL; | ||
7273 | |||
7274 | spin_lock(&root->fs_info->delalloc_lock); | ||
7275 | while (!list_empty(&root->fs_info->delalloc_inodes)) { | ||
7276 | binode = list_entry(root->fs_info->delalloc_inodes.next, | ||
7277 | struct btrfs_inode, delalloc_inodes); | ||
7278 | inode = igrab(&binode->vfs_inode); | ||
7279 | if (inode) { | ||
7280 | list_move_tail(&binode->delalloc_inodes, | ||
7281 | &root->fs_info->delalloc_inodes); | ||
7282 | break; | ||
7283 | } | ||
7284 | |||
7285 | list_del_init(&binode->delalloc_inodes); | ||
7286 | cond_resched_lock(&root->fs_info->delalloc_lock); | ||
7287 | } | ||
7288 | spin_unlock(&root->fs_info->delalloc_lock); | ||
7289 | |||
7290 | if (inode) { | ||
7291 | if (sync) { | ||
7292 | filemap_write_and_wait(inode->i_mapping); | ||
7293 | /* | ||
7294 | * We have to do this because compression doesn't | ||
7295 | * actually set PG_writeback until it submits the pages | ||
7296 | * for IO, which happens in an async thread, so we could | ||
7297 | * race and not actually wait for any writeback pages | ||
7298 | * because they've not been submitted yet. Technically | ||
7299 | * this could still be the case for the ordered stuff | ||
7300 | * since the async thread may not have started to do its | ||
7301 | * work yet. If this becomes the case then we need to | ||
7302 | * figure out a way to make sure that in writepage we | ||
7303 | * wait for any async pages to be submitted before | ||
7304 | * returning so that fdatawait does what its supposed to | ||
7305 | * do. | ||
7306 | */ | ||
7307 | btrfs_wait_ordered_range(inode, 0, (u64)-1); | ||
7308 | } else { | ||
7309 | filemap_flush(inode->i_mapping); | ||
7310 | } | ||
7311 | if (delay_iput) | ||
7312 | btrfs_add_delayed_iput(inode); | ||
7313 | else | ||
7314 | iput(inode); | ||
7315 | return 1; | ||
7316 | } | ||
7317 | return 0; | ||
7318 | } | ||
7319 | |||
7320 | static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | 7091 | static int btrfs_symlink(struct inode *dir, struct dentry *dentry, |
7321 | const char *symname) | 7092 | const char *symname) |
7322 | { | 7093 | { |
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 7ab39db3db0f..ed8c055ab70f 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -1402,7 +1402,7 @@ static noinline int search_ioctl(struct inode *inode, | |||
1402 | } | 1402 | } |
1403 | ret = copy_to_sk(root, path, &key, sk, args->buf, | 1403 | ret = copy_to_sk(root, path, &key, sk, args->buf, |
1404 | &sk_offset, &num_found); | 1404 | &sk_offset, &num_found); |
1405 | btrfs_release_path(root, path); | 1405 | btrfs_release_path(path); |
1406 | if (ret || num_found >= sk->nr_items) | 1406 | if (ret || num_found >= sk->nr_items) |
1407 | break; | 1407 | break; |
1408 | 1408 | ||
@@ -1509,7 +1509,7 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info, | |||
1509 | if (key.offset == BTRFS_FIRST_FREE_OBJECTID) | 1509 | if (key.offset == BTRFS_FIRST_FREE_OBJECTID) |
1510 | break; | 1510 | break; |
1511 | 1511 | ||
1512 | btrfs_release_path(root, path); | 1512 | btrfs_release_path(path); |
1513 | key.objectid = key.offset; | 1513 | key.objectid = key.offset; |
1514 | key.offset = (u64)-1; | 1514 | key.offset = (u64)-1; |
1515 | dirid = key.objectid; | 1515 | dirid = key.objectid; |
@@ -1988,7 +1988,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, | |||
1988 | datal = btrfs_file_extent_ram_bytes(leaf, | 1988 | datal = btrfs_file_extent_ram_bytes(leaf, |
1989 | extent); | 1989 | extent); |
1990 | } | 1990 | } |
1991 | btrfs_release_path(root, path); | 1991 | btrfs_release_path(path); |
1992 | 1992 | ||
1993 | if (key.offset + datal <= off || | 1993 | if (key.offset + datal <= off || |
1994 | key.offset >= off+len) | 1994 | key.offset >= off+len) |
@@ -2098,7 +2098,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, | |||
2098 | } | 2098 | } |
2099 | 2099 | ||
2100 | btrfs_mark_buffer_dirty(leaf); | 2100 | btrfs_mark_buffer_dirty(leaf); |
2101 | btrfs_release_path(root, path); | 2101 | btrfs_release_path(path); |
2102 | 2102 | ||
2103 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; | 2103 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
2104 | 2104 | ||
@@ -2119,12 +2119,12 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, | |||
2119 | btrfs_end_transaction(trans, root); | 2119 | btrfs_end_transaction(trans, root); |
2120 | } | 2120 | } |
2121 | next: | 2121 | next: |
2122 | btrfs_release_path(root, path); | 2122 | btrfs_release_path(path); |
2123 | key.offset++; | 2123 | key.offset++; |
2124 | } | 2124 | } |
2125 | ret = 0; | 2125 | ret = 0; |
2126 | out: | 2126 | out: |
2127 | btrfs_release_path(root, path); | 2127 | btrfs_release_path(path); |
2128 | unlock_extent(&BTRFS_I(src)->io_tree, off, off+len, GFP_NOFS); | 2128 | unlock_extent(&BTRFS_I(src)->io_tree, off, off+len, GFP_NOFS); |
2129 | out_unlock: | 2129 | out_unlock: |
2130 | mutex_unlock(&src->i_mutex); | 2130 | mutex_unlock(&src->i_mutex); |
diff --git a/fs/btrfs/locking.c b/fs/btrfs/locking.c index 6151f2ea38bb..66fa43dc3f0f 100644 --- a/fs/btrfs/locking.c +++ b/fs/btrfs/locking.c | |||
@@ -185,31 +185,6 @@ sleep: | |||
185 | return 0; | 185 | return 0; |
186 | } | 186 | } |
187 | 187 | ||
188 | /* | ||
189 | * Very quick trylock, this does not spin or schedule. It returns | ||
190 | * 1 with the spinlock held if it was able to take the lock, or it | ||
191 | * returns zero if it was unable to take the lock. | ||
192 | * | ||
193 | * After this call, scheduling is not safe without first calling | ||
194 | * btrfs_set_lock_blocking() | ||
195 | */ | ||
196 | int btrfs_try_tree_lock(struct extent_buffer *eb) | ||
197 | { | ||
198 | if (spin_trylock(&eb->lock)) { | ||
199 | if (test_bit(EXTENT_BUFFER_BLOCKING, &eb->bflags)) { | ||
200 | /* | ||
201 | * we've got the spinlock, but the real owner is | ||
202 | * blocking. Drop the spinlock and return failure | ||
203 | */ | ||
204 | spin_unlock(&eb->lock); | ||
205 | return 0; | ||
206 | } | ||
207 | return 1; | ||
208 | } | ||
209 | /* someone else has the spinlock giveup */ | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | int btrfs_tree_unlock(struct extent_buffer *eb) | 188 | int btrfs_tree_unlock(struct extent_buffer *eb) |
214 | { | 189 | { |
215 | /* | 190 | /* |
diff --git a/fs/btrfs/locking.h b/fs/btrfs/locking.h index 6c4ce457168c..5c33a560a2f1 100644 --- a/fs/btrfs/locking.h +++ b/fs/btrfs/locking.h | |||
@@ -21,8 +21,6 @@ | |||
21 | 21 | ||
22 | int btrfs_tree_lock(struct extent_buffer *eb); | 22 | int btrfs_tree_lock(struct extent_buffer *eb); |
23 | int btrfs_tree_unlock(struct extent_buffer *eb); | 23 | int btrfs_tree_unlock(struct extent_buffer *eb); |
24 | |||
25 | int btrfs_try_tree_lock(struct extent_buffer *eb); | ||
26 | int btrfs_try_spin_lock(struct extent_buffer *eb); | 24 | int btrfs_try_spin_lock(struct extent_buffer *eb); |
27 | 25 | ||
28 | void btrfs_set_lock_blocking(struct extent_buffer *eb); | 26 | void btrfs_set_lock_blocking(struct extent_buffer *eb); |
diff --git a/fs/btrfs/ref-cache.c b/fs/btrfs/ref-cache.c index a97314cf6bd6..82d569cb6267 100644 --- a/fs/btrfs/ref-cache.c +++ b/fs/btrfs/ref-cache.c | |||
@@ -23,56 +23,6 @@ | |||
23 | #include "ref-cache.h" | 23 | #include "ref-cache.h" |
24 | #include "transaction.h" | 24 | #include "transaction.h" |
25 | 25 | ||
26 | /* | ||
27 | * leaf refs are used to cache the information about which extents | ||
28 | * a given leaf has references on. This allows us to process that leaf | ||
29 | * in btrfs_drop_snapshot without needing to read it back from disk. | ||
30 | */ | ||
31 | |||
32 | /* | ||
33 | * kmalloc a leaf reference struct and update the counters for the | ||
34 | * total ref cache size | ||
35 | */ | ||
36 | struct btrfs_leaf_ref *btrfs_alloc_leaf_ref(struct btrfs_root *root, | ||
37 | int nr_extents) | ||
38 | { | ||
39 | struct btrfs_leaf_ref *ref; | ||
40 | size_t size = btrfs_leaf_ref_size(nr_extents); | ||
41 | |||
42 | ref = kmalloc(size, GFP_NOFS); | ||
43 | if (ref) { | ||
44 | spin_lock(&root->fs_info->ref_cache_lock); | ||
45 | root->fs_info->total_ref_cache_size += size; | ||
46 | spin_unlock(&root->fs_info->ref_cache_lock); | ||
47 | |||
48 | memset(ref, 0, sizeof(*ref)); | ||
49 | atomic_set(&ref->usage, 1); | ||
50 | INIT_LIST_HEAD(&ref->list); | ||
51 | } | ||
52 | return ref; | ||
53 | } | ||
54 | |||
55 | /* | ||
56 | * free a leaf reference struct and update the counters for the | ||
57 | * total ref cache size | ||
58 | */ | ||
59 | void btrfs_free_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref) | ||
60 | { | ||
61 | if (!ref) | ||
62 | return; | ||
63 | WARN_ON(atomic_read(&ref->usage) == 0); | ||
64 | if (atomic_dec_and_test(&ref->usage)) { | ||
65 | size_t size = btrfs_leaf_ref_size(ref->nritems); | ||
66 | |||
67 | BUG_ON(ref->in_tree); | ||
68 | kfree(ref); | ||
69 | |||
70 | spin_lock(&root->fs_info->ref_cache_lock); | ||
71 | root->fs_info->total_ref_cache_size -= size; | ||
72 | spin_unlock(&root->fs_info->ref_cache_lock); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | static struct rb_node *tree_insert(struct rb_root *root, u64 bytenr, | 26 | static struct rb_node *tree_insert(struct rb_root *root, u64 bytenr, |
77 | struct rb_node *node) | 27 | struct rb_node *node) |
78 | { | 28 | { |
@@ -116,117 +66,3 @@ static struct rb_node *tree_search(struct rb_root *root, u64 bytenr) | |||
116 | } | 66 | } |
117 | return NULL; | 67 | return NULL; |
118 | } | 68 | } |
119 | |||
120 | int btrfs_remove_leaf_refs(struct btrfs_root *root, u64 max_root_gen, | ||
121 | int shared) | ||
122 | { | ||
123 | struct btrfs_leaf_ref *ref = NULL; | ||
124 | struct btrfs_leaf_ref_tree *tree = root->ref_tree; | ||
125 | |||
126 | if (shared) | ||
127 | tree = &root->fs_info->shared_ref_tree; | ||
128 | if (!tree) | ||
129 | return 0; | ||
130 | |||
131 | spin_lock(&tree->lock); | ||
132 | while (!list_empty(&tree->list)) { | ||
133 | ref = list_entry(tree->list.next, struct btrfs_leaf_ref, list); | ||
134 | BUG_ON(ref->tree != tree); | ||
135 | if (ref->root_gen > max_root_gen) | ||
136 | break; | ||
137 | if (!xchg(&ref->in_tree, 0)) { | ||
138 | cond_resched_lock(&tree->lock); | ||
139 | continue; | ||
140 | } | ||
141 | |||
142 | rb_erase(&ref->rb_node, &tree->root); | ||
143 | list_del_init(&ref->list); | ||
144 | |||
145 | spin_unlock(&tree->lock); | ||
146 | btrfs_free_leaf_ref(root, ref); | ||
147 | cond_resched(); | ||
148 | spin_lock(&tree->lock); | ||
149 | } | ||
150 | spin_unlock(&tree->lock); | ||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | /* | ||
155 | * find the leaf ref for a given extent. This returns the ref struct with | ||
156 | * a usage reference incremented | ||
157 | */ | ||
158 | struct btrfs_leaf_ref *btrfs_lookup_leaf_ref(struct btrfs_root *root, | ||
159 | u64 bytenr) | ||
160 | { | ||
161 | struct rb_node *rb; | ||
162 | struct btrfs_leaf_ref *ref = NULL; | ||
163 | struct btrfs_leaf_ref_tree *tree = root->ref_tree; | ||
164 | again: | ||
165 | if (tree) { | ||
166 | spin_lock(&tree->lock); | ||
167 | rb = tree_search(&tree->root, bytenr); | ||
168 | if (rb) | ||
169 | ref = rb_entry(rb, struct btrfs_leaf_ref, rb_node); | ||
170 | if (ref) | ||
171 | atomic_inc(&ref->usage); | ||
172 | spin_unlock(&tree->lock); | ||
173 | if (ref) | ||
174 | return ref; | ||
175 | } | ||
176 | if (tree != &root->fs_info->shared_ref_tree) { | ||
177 | tree = &root->fs_info->shared_ref_tree; | ||
178 | goto again; | ||
179 | } | ||
180 | return NULL; | ||
181 | } | ||
182 | |||
183 | /* | ||
184 | * add a fully filled in leaf ref struct | ||
185 | * remove all the refs older than a given root generation | ||
186 | */ | ||
187 | int btrfs_add_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref, | ||
188 | int shared) | ||
189 | { | ||
190 | int ret = 0; | ||
191 | struct rb_node *rb; | ||
192 | struct btrfs_leaf_ref_tree *tree = root->ref_tree; | ||
193 | |||
194 | if (shared) | ||
195 | tree = &root->fs_info->shared_ref_tree; | ||
196 | |||
197 | spin_lock(&tree->lock); | ||
198 | rb = tree_insert(&tree->root, ref->bytenr, &ref->rb_node); | ||
199 | if (rb) { | ||
200 | ret = -EEXIST; | ||
201 | } else { | ||
202 | atomic_inc(&ref->usage); | ||
203 | ref->tree = tree; | ||
204 | ref->in_tree = 1; | ||
205 | list_add_tail(&ref->list, &tree->list); | ||
206 | } | ||
207 | spin_unlock(&tree->lock); | ||
208 | return ret; | ||
209 | } | ||
210 | |||
211 | /* | ||
212 | * remove a single leaf ref from the tree. This drops the ref held by the tree | ||
213 | * only | ||
214 | */ | ||
215 | int btrfs_remove_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref) | ||
216 | { | ||
217 | struct btrfs_leaf_ref_tree *tree; | ||
218 | |||
219 | if (!xchg(&ref->in_tree, 0)) | ||
220 | return 0; | ||
221 | |||
222 | tree = ref->tree; | ||
223 | spin_lock(&tree->lock); | ||
224 | |||
225 | rb_erase(&ref->rb_node, &tree->root); | ||
226 | list_del_init(&ref->list); | ||
227 | |||
228 | spin_unlock(&tree->lock); | ||
229 | |||
230 | btrfs_free_leaf_ref(root, ref); | ||
231 | return 0; | ||
232 | } | ||
diff --git a/fs/btrfs/ref-cache.h b/fs/btrfs/ref-cache.h index e2a55cb2072b..24f7001f6387 100644 --- a/fs/btrfs/ref-cache.h +++ b/fs/btrfs/ref-cache.h | |||
@@ -49,28 +49,4 @@ static inline size_t btrfs_leaf_ref_size(int nr_extents) | |||
49 | return sizeof(struct btrfs_leaf_ref) + | 49 | return sizeof(struct btrfs_leaf_ref) + |
50 | sizeof(struct btrfs_extent_info) * nr_extents; | 50 | sizeof(struct btrfs_extent_info) * nr_extents; |
51 | } | 51 | } |
52 | |||
53 | static inline void btrfs_leaf_ref_tree_init(struct btrfs_leaf_ref_tree *tree) | ||
54 | { | ||
55 | tree->root = RB_ROOT; | ||
56 | INIT_LIST_HEAD(&tree->list); | ||
57 | spin_lock_init(&tree->lock); | ||
58 | } | ||
59 | |||
60 | static inline int btrfs_leaf_ref_tree_empty(struct btrfs_leaf_ref_tree *tree) | ||
61 | { | ||
62 | return RB_EMPTY_ROOT(&tree->root); | ||
63 | } | ||
64 | |||
65 | void btrfs_leaf_ref_tree_init(struct btrfs_leaf_ref_tree *tree); | ||
66 | struct btrfs_leaf_ref *btrfs_alloc_leaf_ref(struct btrfs_root *root, | ||
67 | int nr_extents); | ||
68 | void btrfs_free_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref); | ||
69 | struct btrfs_leaf_ref *btrfs_lookup_leaf_ref(struct btrfs_root *root, | ||
70 | u64 bytenr); | ||
71 | int btrfs_add_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref, | ||
72 | int shared); | ||
73 | int btrfs_remove_leaf_refs(struct btrfs_root *root, u64 max_root_gen, | ||
74 | int shared); | ||
75 | int btrfs_remove_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref); | ||
76 | #endif | 52 | #endif |
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 4b5b91cf48e2..051992c7fcc9 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c | |||
@@ -508,6 +508,7 @@ static int update_backref_cache(struct btrfs_trans_handle *trans, | |||
508 | return 1; | 508 | return 1; |
509 | } | 509 | } |
510 | 510 | ||
511 | |||
511 | static int should_ignore_root(struct btrfs_root *root) | 512 | static int should_ignore_root(struct btrfs_root *root) |
512 | { | 513 | { |
513 | struct btrfs_root *reloc_root; | 514 | struct btrfs_root *reloc_root; |
@@ -530,7 +531,6 @@ static int should_ignore_root(struct btrfs_root *root) | |||
530 | */ | 531 | */ |
531 | return 1; | 532 | return 1; |
532 | } | 533 | } |
533 | |||
534 | /* | 534 | /* |
535 | * find reloc tree by address of tree root | 535 | * find reloc tree by address of tree root |
536 | */ | 536 | */ |
@@ -962,7 +962,7 @@ again: | |||
962 | lower = upper; | 962 | lower = upper; |
963 | upper = NULL; | 963 | upper = NULL; |
964 | } | 964 | } |
965 | btrfs_release_path(root, path2); | 965 | btrfs_release_path(path2); |
966 | next: | 966 | next: |
967 | if (ptr < end) { | 967 | if (ptr < end) { |
968 | ptr += btrfs_extent_inline_ref_size(key.type); | 968 | ptr += btrfs_extent_inline_ref_size(key.type); |
@@ -975,7 +975,7 @@ next: | |||
975 | if (ptr >= end) | 975 | if (ptr >= end) |
976 | path1->slots[0]++; | 976 | path1->slots[0]++; |
977 | } | 977 | } |
978 | btrfs_release_path(rc->extent_root, path1); | 978 | btrfs_release_path(path1); |
979 | 979 | ||
980 | cur->checked = 1; | 980 | cur->checked = 1; |
981 | WARN_ON(exist); | 981 | WARN_ON(exist); |
@@ -1750,7 +1750,7 @@ again: | |||
1750 | 1750 | ||
1751 | btrfs_node_key_to_cpu(path->nodes[level], &key, | 1751 | btrfs_node_key_to_cpu(path->nodes[level], &key, |
1752 | path->slots[level]); | 1752 | path->slots[level]); |
1753 | btrfs_release_path(src, path); | 1753 | btrfs_release_path(path); |
1754 | 1754 | ||
1755 | path->lowest_level = level; | 1755 | path->lowest_level = level; |
1756 | ret = btrfs_search_slot(trans, src, &key, path, 0, 1); | 1756 | ret = btrfs_search_slot(trans, src, &key, path, 0, 1); |
@@ -2499,7 +2499,7 @@ static int do_relocation(struct btrfs_trans_handle *trans, | |||
2499 | path->locks[upper->level] = 0; | 2499 | path->locks[upper->level] = 0; |
2500 | 2500 | ||
2501 | slot = path->slots[upper->level]; | 2501 | slot = path->slots[upper->level]; |
2502 | btrfs_release_path(NULL, path); | 2502 | btrfs_release_path(path); |
2503 | } else { | 2503 | } else { |
2504 | ret = btrfs_bin_search(upper->eb, key, upper->level, | 2504 | ret = btrfs_bin_search(upper->eb, key, upper->level, |
2505 | &slot); | 2505 | &slot); |
@@ -2740,7 +2740,7 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, | |||
2740 | } else { | 2740 | } else { |
2741 | path->lowest_level = node->level; | 2741 | path->lowest_level = node->level; |
2742 | ret = btrfs_search_slot(trans, root, key, path, 0, 1); | 2742 | ret = btrfs_search_slot(trans, root, key, path, 0, 1); |
2743 | btrfs_release_path(root, path); | 2743 | btrfs_release_path(path); |
2744 | if (ret > 0) | 2744 | if (ret > 0) |
2745 | ret = 0; | 2745 | ret = 0; |
2746 | } | 2746 | } |
@@ -2873,7 +2873,7 @@ int setup_extent_mapping(struct inode *inode, u64 start, u64 end, | |||
2873 | struct extent_map *em; | 2873 | struct extent_map *em; |
2874 | int ret = 0; | 2874 | int ret = 0; |
2875 | 2875 | ||
2876 | em = alloc_extent_map(GFP_NOFS); | 2876 | em = alloc_extent_map(); |
2877 | if (!em) | 2877 | if (!em) |
2878 | return -ENOMEM; | 2878 | return -ENOMEM; |
2879 | 2879 | ||
@@ -3122,7 +3122,7 @@ static int add_tree_block(struct reloc_control *rc, | |||
3122 | #endif | 3122 | #endif |
3123 | } | 3123 | } |
3124 | 3124 | ||
3125 | btrfs_release_path(rc->extent_root, path); | 3125 | btrfs_release_path(path); |
3126 | 3126 | ||
3127 | BUG_ON(level == -1); | 3127 | BUG_ON(level == -1); |
3128 | 3128 | ||
@@ -3223,7 +3223,7 @@ static int delete_block_group_cache(struct btrfs_fs_info *fs_info, | |||
3223 | key.offset = 0; | 3223 | key.offset = 0; |
3224 | 3224 | ||
3225 | inode = btrfs_iget(fs_info->sb, &key, root, NULL); | 3225 | inode = btrfs_iget(fs_info->sb, &key, root, NULL); |
3226 | if (!inode || IS_ERR(inode) || is_bad_inode(inode)) { | 3226 | if (IS_ERR_OR_NULL(inode) || is_bad_inode(inode)) { |
3227 | if (inode && !IS_ERR(inode)) | 3227 | if (inode && !IS_ERR(inode)) |
3228 | iput(inode); | 3228 | iput(inode); |
3229 | return -ENOENT; | 3229 | return -ENOENT; |
@@ -3508,7 +3508,7 @@ int add_data_references(struct reloc_control *rc, | |||
3508 | } | 3508 | } |
3509 | path->slots[0]++; | 3509 | path->slots[0]++; |
3510 | } | 3510 | } |
3511 | btrfs_release_path(rc->extent_root, path); | 3511 | btrfs_release_path(path); |
3512 | if (err) | 3512 | if (err) |
3513 | free_block_list(blocks); | 3513 | free_block_list(blocks); |
3514 | return err; | 3514 | return err; |
@@ -3571,7 +3571,7 @@ next: | |||
3571 | EXTENT_DIRTY); | 3571 | EXTENT_DIRTY); |
3572 | 3572 | ||
3573 | if (ret == 0 && start <= key.objectid) { | 3573 | if (ret == 0 && start <= key.objectid) { |
3574 | btrfs_release_path(rc->extent_root, path); | 3574 | btrfs_release_path(path); |
3575 | rc->search_start = end + 1; | 3575 | rc->search_start = end + 1; |
3576 | } else { | 3576 | } else { |
3577 | rc->search_start = key.objectid + key.offset; | 3577 | rc->search_start = key.objectid + key.offset; |
@@ -3579,7 +3579,7 @@ next: | |||
3579 | return 0; | 3579 | return 0; |
3580 | } | 3580 | } |
3581 | } | 3581 | } |
3582 | btrfs_release_path(rc->extent_root, path); | 3582 | btrfs_release_path(path); |
3583 | return ret; | 3583 | return ret; |
3584 | } | 3584 | } |
3585 | 3585 | ||
@@ -3716,7 +3716,7 @@ restart: | |||
3716 | flags = BTRFS_EXTENT_FLAG_DATA; | 3716 | flags = BTRFS_EXTENT_FLAG_DATA; |
3717 | 3717 | ||
3718 | if (path_change) { | 3718 | if (path_change) { |
3719 | btrfs_release_path(rc->extent_root, path); | 3719 | btrfs_release_path(path); |
3720 | 3720 | ||
3721 | path->search_commit_root = 1; | 3721 | path->search_commit_root = 1; |
3722 | path->skip_locking = 1; | 3722 | path->skip_locking = 1; |
@@ -3739,7 +3739,7 @@ restart: | |||
3739 | (flags & BTRFS_EXTENT_FLAG_DATA)) { | 3739 | (flags & BTRFS_EXTENT_FLAG_DATA)) { |
3740 | ret = add_data_references(rc, &key, path, &blocks); | 3740 | ret = add_data_references(rc, &key, path, &blocks); |
3741 | } else { | 3741 | } else { |
3742 | btrfs_release_path(rc->extent_root, path); | 3742 | btrfs_release_path(path); |
3743 | ret = 0; | 3743 | ret = 0; |
3744 | } | 3744 | } |
3745 | if (ret < 0) { | 3745 | if (ret < 0) { |
@@ -3802,7 +3802,7 @@ restart: | |||
3802 | } | 3802 | } |
3803 | } | 3803 | } |
3804 | 3804 | ||
3805 | btrfs_release_path(rc->extent_root, path); | 3805 | btrfs_release_path(path); |
3806 | clear_extent_bits(&rc->processed_blocks, 0, (u64)-1, EXTENT_DIRTY, | 3806 | clear_extent_bits(&rc->processed_blocks, 0, (u64)-1, EXTENT_DIRTY, |
3807 | GFP_NOFS); | 3807 | GFP_NOFS); |
3808 | 3808 | ||
@@ -3870,7 +3870,7 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans, | |||
3870 | btrfs_set_inode_flags(leaf, item, BTRFS_INODE_NOCOMPRESS | | 3870 | btrfs_set_inode_flags(leaf, item, BTRFS_INODE_NOCOMPRESS | |
3871 | BTRFS_INODE_PREALLOC); | 3871 | BTRFS_INODE_PREALLOC); |
3872 | btrfs_mark_buffer_dirty(leaf); | 3872 | btrfs_mark_buffer_dirty(leaf); |
3873 | btrfs_release_path(root, path); | 3873 | btrfs_release_path(path); |
3874 | out: | 3874 | out: |
3875 | btrfs_free_path(path); | 3875 | btrfs_free_path(path); |
3876 | return ret; | 3876 | return ret; |
@@ -3938,7 +3938,7 @@ static struct reloc_control *alloc_reloc_control(void) | |||
3938 | INIT_LIST_HEAD(&rc->reloc_roots); | 3938 | INIT_LIST_HEAD(&rc->reloc_roots); |
3939 | backref_cache_init(&rc->backref_cache); | 3939 | backref_cache_init(&rc->backref_cache); |
3940 | mapping_tree_init(&rc->reloc_root_tree); | 3940 | mapping_tree_init(&rc->reloc_root_tree); |
3941 | extent_io_tree_init(&rc->processed_blocks, NULL, GFP_NOFS); | 3941 | extent_io_tree_init(&rc->processed_blocks, NULL); |
3942 | return rc; | 3942 | return rc; |
3943 | } | 3943 | } |
3944 | 3944 | ||
@@ -4112,7 +4112,7 @@ int btrfs_recover_relocation(struct btrfs_root *root) | |||
4112 | } | 4112 | } |
4113 | leaf = path->nodes[0]; | 4113 | leaf = path->nodes[0]; |
4114 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); | 4114 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); |
4115 | btrfs_release_path(root->fs_info->tree_root, path); | 4115 | btrfs_release_path(path); |
4116 | 4116 | ||
4117 | if (key.objectid != BTRFS_TREE_RELOC_OBJECTID || | 4117 | if (key.objectid != BTRFS_TREE_RELOC_OBJECTID || |
4118 | key.type != BTRFS_ROOT_ITEM_KEY) | 4118 | key.type != BTRFS_ROOT_ITEM_KEY) |
@@ -4144,7 +4144,7 @@ int btrfs_recover_relocation(struct btrfs_root *root) | |||
4144 | 4144 | ||
4145 | key.offset--; | 4145 | key.offset--; |
4146 | } | 4146 | } |
4147 | btrfs_release_path(root->fs_info->tree_root, path); | 4147 | btrfs_release_path(path); |
4148 | 4148 | ||
4149 | if (list_empty(&reloc_roots)) | 4149 | if (list_empty(&reloc_roots)) |
4150 | goto out; | 4150 | goto out; |
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c index 6928bff62daa..3bcfe5a7c330 100644 --- a/fs/btrfs/root-tree.c +++ b/fs/btrfs/root-tree.c | |||
@@ -22,53 +22,6 @@ | |||
22 | #include "print-tree.h" | 22 | #include "print-tree.h" |
23 | 23 | ||
24 | /* | 24 | /* |
25 | * search forward for a root, starting with objectid 'search_start' | ||
26 | * if a root key is found, the objectid we find is filled into 'found_objectid' | ||
27 | * and 0 is returned. < 0 is returned on error, 1 if there is nothing | ||
28 | * left in the tree. | ||
29 | */ | ||
30 | int btrfs_search_root(struct btrfs_root *root, u64 search_start, | ||
31 | u64 *found_objectid) | ||
32 | { | ||
33 | struct btrfs_path *path; | ||
34 | struct btrfs_key search_key; | ||
35 | int ret; | ||
36 | |||
37 | root = root->fs_info->tree_root; | ||
38 | search_key.objectid = search_start; | ||
39 | search_key.type = (u8)-1; | ||
40 | search_key.offset = (u64)-1; | ||
41 | |||
42 | path = btrfs_alloc_path(); | ||
43 | BUG_ON(!path); | ||
44 | again: | ||
45 | ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); | ||
46 | if (ret < 0) | ||
47 | goto out; | ||
48 | if (ret == 0) { | ||
49 | ret = 1; | ||
50 | goto out; | ||
51 | } | ||
52 | if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) { | ||
53 | ret = btrfs_next_leaf(root, path); | ||
54 | if (ret) | ||
55 | goto out; | ||
56 | } | ||
57 | btrfs_item_key_to_cpu(path->nodes[0], &search_key, path->slots[0]); | ||
58 | if (search_key.type != BTRFS_ROOT_ITEM_KEY) { | ||
59 | search_key.offset++; | ||
60 | btrfs_release_path(root, path); | ||
61 | goto again; | ||
62 | } | ||
63 | ret = 0; | ||
64 | *found_objectid = search_key.objectid; | ||
65 | |||
66 | out: | ||
67 | btrfs_free_path(path); | ||
68 | return ret; | ||
69 | } | ||
70 | |||
71 | /* | ||
72 | * lookup the root with the highest offset for a given objectid. The key we do | 25 | * lookup the root with the highest offset for a given objectid. The key we do |
73 | * find is copied into 'key'. If we find something return 0, otherwise 1, < 0 | 26 | * find is copied into 'key'. If we find something return 0, otherwise 1, < 0 |
74 | * on error. | 27 | * on error. |
@@ -230,7 +183,7 @@ again: | |||
230 | 183 | ||
231 | memcpy(&found_key, &key, sizeof(key)); | 184 | memcpy(&found_key, &key, sizeof(key)); |
232 | key.offset++; | 185 | key.offset++; |
233 | btrfs_release_path(root, path); | 186 | btrfs_release_path(path); |
234 | dead_root = | 187 | dead_root = |
235 | btrfs_read_fs_root_no_radix(root->fs_info->tree_root, | 188 | btrfs_read_fs_root_no_radix(root->fs_info->tree_root, |
236 | &found_key); | 189 | &found_key); |
@@ -292,7 +245,7 @@ int btrfs_find_orphan_roots(struct btrfs_root *tree_root) | |||
292 | } | 245 | } |
293 | 246 | ||
294 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); | 247 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); |
295 | btrfs_release_path(tree_root, path); | 248 | btrfs_release_path(path); |
296 | 249 | ||
297 | if (key.objectid != BTRFS_ORPHAN_OBJECTID || | 250 | if (key.objectid != BTRFS_ORPHAN_OBJECTID || |
298 | key.type != BTRFS_ORPHAN_ITEM_KEY) | 251 | key.type != BTRFS_ORPHAN_ITEM_KEY) |
@@ -390,7 +343,7 @@ again: | |||
390 | err = -ENOENT; | 343 | err = -ENOENT; |
391 | 344 | ||
392 | if (key.type == BTRFS_ROOT_BACKREF_KEY) { | 345 | if (key.type == BTRFS_ROOT_BACKREF_KEY) { |
393 | btrfs_release_path(tree_root, path); | 346 | btrfs_release_path(path); |
394 | key.objectid = ref_id; | 347 | key.objectid = ref_id; |
395 | key.type = BTRFS_ROOT_REF_KEY; | 348 | key.type = BTRFS_ROOT_REF_KEY; |
396 | key.offset = root_id; | 349 | key.offset = root_id; |
@@ -463,7 +416,7 @@ again: | |||
463 | btrfs_mark_buffer_dirty(leaf); | 416 | btrfs_mark_buffer_dirty(leaf); |
464 | 417 | ||
465 | if (key.type == BTRFS_ROOT_BACKREF_KEY) { | 418 | if (key.type == BTRFS_ROOT_BACKREF_KEY) { |
466 | btrfs_release_path(tree_root, path); | 419 | btrfs_release_path(path); |
467 | key.objectid = ref_id; | 420 | key.objectid = ref_id; |
468 | key.type = BTRFS_ROOT_REF_KEY; | 421 | key.type = BTRFS_ROOT_REF_KEY; |
469 | key.offset = root_id; | 422 | key.offset = root_id; |
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index cc5a2a8a5acb..fb72e2bea882 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -740,7 +740,7 @@ static int btrfs_set_super(struct super_block *s, void *data) | |||
740 | * for multiple device setup. Make sure to keep it in sync. | 740 | * for multiple device setup. Make sure to keep it in sync. |
741 | */ | 741 | */ |
742 | static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, | 742 | static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, |
743 | const char *dev_name, void *data) | 743 | const char *device_name, void *data) |
744 | { | 744 | { |
745 | struct block_device *bdev = NULL; | 745 | struct block_device *bdev = NULL; |
746 | struct super_block *s; | 746 | struct super_block *s; |
@@ -763,7 +763,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, | |||
763 | if (error) | 763 | if (error) |
764 | return ERR_PTR(error); | 764 | return ERR_PTR(error); |
765 | 765 | ||
766 | error = btrfs_scan_one_device(dev_name, mode, fs_type, &fs_devices); | 766 | error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices); |
767 | if (error) | 767 | if (error) |
768 | goto error_free_subvol_name; | 768 | goto error_free_subvol_name; |
769 | 769 | ||
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 4ce16ef702a3..c3c223ae6691 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c | |||
@@ -174,86 +174,9 @@ static const struct sysfs_ops btrfs_root_attr_ops = { | |||
174 | .store = btrfs_root_attr_store, | 174 | .store = btrfs_root_attr_store, |
175 | }; | 175 | }; |
176 | 176 | ||
177 | static struct kobj_type btrfs_root_ktype = { | ||
178 | .default_attrs = btrfs_root_attrs, | ||
179 | .sysfs_ops = &btrfs_root_attr_ops, | ||
180 | .release = btrfs_root_release, | ||
181 | }; | ||
182 | |||
183 | static struct kobj_type btrfs_super_ktype = { | ||
184 | .default_attrs = btrfs_super_attrs, | ||
185 | .sysfs_ops = &btrfs_super_attr_ops, | ||
186 | .release = btrfs_super_release, | ||
187 | }; | ||
188 | |||
189 | /* /sys/fs/btrfs/ entry */ | 177 | /* /sys/fs/btrfs/ entry */ |
190 | static struct kset *btrfs_kset; | 178 | static struct kset *btrfs_kset; |
191 | 179 | ||
192 | int btrfs_sysfs_add_super(struct btrfs_fs_info *fs) | ||
193 | { | ||
194 | int error; | ||
195 | char *name; | ||
196 | char c; | ||
197 | int len = strlen(fs->sb->s_id) + 1; | ||
198 | int i; | ||
199 | |||
200 | name = kmalloc(len, GFP_NOFS); | ||
201 | if (!name) { | ||
202 | error = -ENOMEM; | ||
203 | goto fail; | ||
204 | } | ||
205 | |||
206 | for (i = 0; i < len; i++) { | ||
207 | c = fs->sb->s_id[i]; | ||
208 | if (c == '/' || c == '\\') | ||
209 | c = '!'; | ||
210 | name[i] = c; | ||
211 | } | ||
212 | name[len] = '\0'; | ||
213 | |||
214 | fs->super_kobj.kset = btrfs_kset; | ||
215 | error = kobject_init_and_add(&fs->super_kobj, &btrfs_super_ktype, | ||
216 | NULL, "%s", name); | ||
217 | kfree(name); | ||
218 | if (error) | ||
219 | goto fail; | ||
220 | |||
221 | return 0; | ||
222 | |||
223 | fail: | ||
224 | printk(KERN_ERR "btrfs: sysfs creation for super failed\n"); | ||
225 | return error; | ||
226 | } | ||
227 | |||
228 | int btrfs_sysfs_add_root(struct btrfs_root *root) | ||
229 | { | ||
230 | int error; | ||
231 | |||
232 | error = kobject_init_and_add(&root->root_kobj, &btrfs_root_ktype, | ||
233 | &root->fs_info->super_kobj, | ||
234 | "%s", root->name); | ||
235 | if (error) | ||
236 | goto fail; | ||
237 | |||
238 | return 0; | ||
239 | |||
240 | fail: | ||
241 | printk(KERN_ERR "btrfs: sysfs creation for root failed\n"); | ||
242 | return error; | ||
243 | } | ||
244 | |||
245 | void btrfs_sysfs_del_root(struct btrfs_root *root) | ||
246 | { | ||
247 | kobject_put(&root->root_kobj); | ||
248 | wait_for_completion(&root->kobj_unregister); | ||
249 | } | ||
250 | |||
251 | void btrfs_sysfs_del_super(struct btrfs_fs_info *fs) | ||
252 | { | ||
253 | kobject_put(&fs->super_kobj); | ||
254 | wait_for_completion(&fs->kobj_unregister); | ||
255 | } | ||
256 | |||
257 | int btrfs_init_sysfs(void) | 180 | int btrfs_init_sysfs(void) |
258 | { | 181 | { |
259 | btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj); | 182 | btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj); |
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 8e7e72341555..33679fc710c6 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -81,8 +81,7 @@ static noinline int join_transaction(struct btrfs_root *root) | |||
81 | INIT_LIST_HEAD(&cur_trans->pending_snapshots); | 81 | INIT_LIST_HEAD(&cur_trans->pending_snapshots); |
82 | list_add_tail(&cur_trans->list, &root->fs_info->trans_list); | 82 | list_add_tail(&cur_trans->list, &root->fs_info->trans_list); |
83 | extent_io_tree_init(&cur_trans->dirty_pages, | 83 | extent_io_tree_init(&cur_trans->dirty_pages, |
84 | root->fs_info->btree_inode->i_mapping, | 84 | root->fs_info->btree_inode->i_mapping); |
85 | GFP_NOFS); | ||
86 | spin_lock(&root->fs_info->new_trans_lock); | 85 | spin_lock(&root->fs_info->new_trans_lock); |
87 | root->fs_info->running_transaction = cur_trans; | 86 | root->fs_info->running_transaction = cur_trans; |
88 | spin_unlock(&root->fs_info->new_trans_lock); | 87 | spin_unlock(&root->fs_info->new_trans_lock); |
@@ -348,49 +347,6 @@ out_unlock: | |||
348 | return ret; | 347 | return ret; |
349 | } | 348 | } |
350 | 349 | ||
351 | #if 0 | ||
352 | /* | ||
353 | * rate limit against the drop_snapshot code. This helps to slow down new | ||
354 | * operations if the drop_snapshot code isn't able to keep up. | ||
355 | */ | ||
356 | static void throttle_on_drops(struct btrfs_root *root) | ||
357 | { | ||
358 | struct btrfs_fs_info *info = root->fs_info; | ||
359 | int harder_count = 0; | ||
360 | |||
361 | harder: | ||
362 | if (atomic_read(&info->throttles)) { | ||
363 | DEFINE_WAIT(wait); | ||
364 | int thr; | ||
365 | thr = atomic_read(&info->throttle_gen); | ||
366 | |||
367 | do { | ||
368 | prepare_to_wait(&info->transaction_throttle, | ||
369 | &wait, TASK_UNINTERRUPTIBLE); | ||
370 | if (!atomic_read(&info->throttles)) { | ||
371 | finish_wait(&info->transaction_throttle, &wait); | ||
372 | break; | ||
373 | } | ||
374 | schedule(); | ||
375 | finish_wait(&info->transaction_throttle, &wait); | ||
376 | } while (thr == atomic_read(&info->throttle_gen)); | ||
377 | harder_count++; | ||
378 | |||
379 | if (root->fs_info->total_ref_cache_size > 1 * 1024 * 1024 && | ||
380 | harder_count < 2) | ||
381 | goto harder; | ||
382 | |||
383 | if (root->fs_info->total_ref_cache_size > 5 * 1024 * 1024 && | ||
384 | harder_count < 10) | ||
385 | goto harder; | ||
386 | |||
387 | if (root->fs_info->total_ref_cache_size > 10 * 1024 * 1024 && | ||
388 | harder_count < 20) | ||
389 | goto harder; | ||
390 | } | ||
391 | } | ||
392 | #endif | ||
393 | |||
394 | void btrfs_throttle(struct btrfs_root *root) | 350 | void btrfs_throttle(struct btrfs_root *root) |
395 | { | 351 | { |
396 | mutex_lock(&root->fs_info->trans_mutex); | 352 | mutex_lock(&root->fs_info->trans_mutex); |
@@ -837,97 +793,6 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly) | |||
837 | return ret; | 793 | return ret; |
838 | } | 794 | } |
839 | 795 | ||
840 | #if 0 | ||
841 | /* | ||
842 | * when dropping snapshots, we generate a ton of delayed refs, and it makes | ||
843 | * sense not to join the transaction while it is trying to flush the current | ||
844 | * queue of delayed refs out. | ||
845 | * | ||
846 | * This is used by the drop snapshot code only | ||
847 | */ | ||
848 | static noinline int wait_transaction_pre_flush(struct btrfs_fs_info *info) | ||
849 | { | ||
850 | DEFINE_WAIT(wait); | ||
851 | |||
852 | mutex_lock(&info->trans_mutex); | ||
853 | while (info->running_transaction && | ||
854 | info->running_transaction->delayed_refs.flushing) { | ||
855 | prepare_to_wait(&info->transaction_wait, &wait, | ||
856 | TASK_UNINTERRUPTIBLE); | ||
857 | mutex_unlock(&info->trans_mutex); | ||
858 | |||
859 | schedule(); | ||
860 | |||
861 | mutex_lock(&info->trans_mutex); | ||
862 | finish_wait(&info->transaction_wait, &wait); | ||
863 | } | ||
864 | mutex_unlock(&info->trans_mutex); | ||
865 | return 0; | ||
866 | } | ||
867 | |||
868 | /* | ||
869 | * Given a list of roots that need to be deleted, call btrfs_drop_snapshot on | ||
870 | * all of them | ||
871 | */ | ||
872 | int btrfs_drop_dead_root(struct btrfs_root *root) | ||
873 | { | ||
874 | struct btrfs_trans_handle *trans; | ||
875 | struct btrfs_root *tree_root = root->fs_info->tree_root; | ||
876 | unsigned long nr; | ||
877 | int ret; | ||
878 | |||
879 | while (1) { | ||
880 | /* | ||
881 | * we don't want to jump in and create a bunch of | ||
882 | * delayed refs if the transaction is starting to close | ||
883 | */ | ||
884 | wait_transaction_pre_flush(tree_root->fs_info); | ||
885 | trans = btrfs_start_transaction(tree_root, 1); | ||
886 | |||
887 | /* | ||
888 | * we've joined a transaction, make sure it isn't | ||
889 | * closing right now | ||
890 | */ | ||
891 | if (trans->transaction->delayed_refs.flushing) { | ||
892 | btrfs_end_transaction(trans, tree_root); | ||
893 | continue; | ||
894 | } | ||
895 | |||
896 | ret = btrfs_drop_snapshot(trans, root); | ||
897 | if (ret != -EAGAIN) | ||
898 | break; | ||
899 | |||
900 | ret = btrfs_update_root(trans, tree_root, | ||
901 | &root->root_key, | ||
902 | &root->root_item); | ||
903 | if (ret) | ||
904 | break; | ||
905 | |||
906 | nr = trans->blocks_used; | ||
907 | ret = btrfs_end_transaction(trans, tree_root); | ||
908 | BUG_ON(ret); | ||
909 | |||
910 | btrfs_btree_balance_dirty(tree_root, nr); | ||
911 | cond_resched(); | ||
912 | } | ||
913 | BUG_ON(ret); | ||
914 | |||
915 | ret = btrfs_del_root(trans, tree_root, &root->root_key); | ||
916 | BUG_ON(ret); | ||
917 | |||
918 | nr = trans->blocks_used; | ||
919 | ret = btrfs_end_transaction(trans, tree_root); | ||
920 | BUG_ON(ret); | ||
921 | |||
922 | free_extent_buffer(root->node); | ||
923 | free_extent_buffer(root->commit_root); | ||
924 | kfree(root); | ||
925 | |||
926 | btrfs_btree_balance_dirty(tree_root, nr); | ||
927 | return ret; | ||
928 | } | ||
929 | #endif | ||
930 | |||
931 | /* | 796 | /* |
932 | * new snapshots need to be created at a very specific time in the | 797 | * new snapshots need to be created at a very specific time in the |
933 | * transaction commit. This does the actual creation | 798 | * transaction commit. This does the actual creation |
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index cb928c6c42e6..804c88639e5d 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h | |||
@@ -101,11 +101,8 @@ struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *r, | |||
101 | int btrfs_wait_for_commit(struct btrfs_root *root, u64 transid); | 101 | int btrfs_wait_for_commit(struct btrfs_root *root, u64 transid); |
102 | int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, | 102 | int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, |
103 | struct btrfs_root *root); | 103 | struct btrfs_root *root); |
104 | int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans, | ||
105 | struct btrfs_root *root); | ||
106 | 104 | ||
107 | int btrfs_add_dead_root(struct btrfs_root *root); | 105 | int btrfs_add_dead_root(struct btrfs_root *root); |
108 | int btrfs_drop_dead_root(struct btrfs_root *root); | ||
109 | int btrfs_defrag_root(struct btrfs_root *root, int cacheonly); | 106 | int btrfs_defrag_root(struct btrfs_root *root, int cacheonly); |
110 | int btrfs_clean_old_snapshots(struct btrfs_root *root); | 107 | int btrfs_clean_old_snapshots(struct btrfs_root *root); |
111 | int btrfs_commit_transaction(struct btrfs_trans_handle *trans, | 108 | int btrfs_commit_transaction(struct btrfs_trans_handle *trans, |
diff --git a/fs/btrfs/tree-defrag.c b/fs/btrfs/tree-defrag.c index 992ab425599d..3b580ee8ab1d 100644 --- a/fs/btrfs/tree-defrag.c +++ b/fs/btrfs/tree-defrag.c | |||
@@ -97,7 +97,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, | |||
97 | ret = 0; | 97 | ret = 0; |
98 | goto out; | 98 | goto out; |
99 | } | 99 | } |
100 | btrfs_release_path(root, path); | 100 | btrfs_release_path(path); |
101 | wret = btrfs_search_slot(trans, root, &key, path, 0, 1); | 101 | wret = btrfs_search_slot(trans, root, &key, path, 0, 1); |
102 | 102 | ||
103 | if (wret < 0) { | 103 | if (wret < 0) { |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 183913bac14e..a794b9f60138 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -333,13 +333,13 @@ static noinline int overwrite_item(struct btrfs_trans_handle *trans, | |||
333 | goto insert; | 333 | goto insert; |
334 | 334 | ||
335 | if (item_size == 0) { | 335 | if (item_size == 0) { |
336 | btrfs_release_path(root, path); | 336 | btrfs_release_path(path); |
337 | return 0; | 337 | return 0; |
338 | } | 338 | } |
339 | dst_copy = kmalloc(item_size, GFP_NOFS); | 339 | dst_copy = kmalloc(item_size, GFP_NOFS); |
340 | src_copy = kmalloc(item_size, GFP_NOFS); | 340 | src_copy = kmalloc(item_size, GFP_NOFS); |
341 | if (!dst_copy || !src_copy) { | 341 | if (!dst_copy || !src_copy) { |
342 | btrfs_release_path(root, path); | 342 | btrfs_release_path(path); |
343 | kfree(dst_copy); | 343 | kfree(dst_copy); |
344 | kfree(src_copy); | 344 | kfree(src_copy); |
345 | return -ENOMEM; | 345 | return -ENOMEM; |
@@ -361,13 +361,13 @@ static noinline int overwrite_item(struct btrfs_trans_handle *trans, | |||
361 | * sync | 361 | * sync |
362 | */ | 362 | */ |
363 | if (ret == 0) { | 363 | if (ret == 0) { |
364 | btrfs_release_path(root, path); | 364 | btrfs_release_path(path); |
365 | return 0; | 365 | return 0; |
366 | } | 366 | } |
367 | 367 | ||
368 | } | 368 | } |
369 | insert: | 369 | insert: |
370 | btrfs_release_path(root, path); | 370 | btrfs_release_path(path); |
371 | /* try to insert the key into the destination tree */ | 371 | /* try to insert the key into the destination tree */ |
372 | ret = btrfs_insert_empty_item(trans, root, path, | 372 | ret = btrfs_insert_empty_item(trans, root, path, |
373 | key, item_size); | 373 | key, item_size); |
@@ -438,7 +438,7 @@ insert: | |||
438 | } | 438 | } |
439 | no_copy: | 439 | no_copy: |
440 | btrfs_mark_buffer_dirty(path->nodes[0]); | 440 | btrfs_mark_buffer_dirty(path->nodes[0]); |
441 | btrfs_release_path(root, path); | 441 | btrfs_release_path(path); |
442 | return 0; | 442 | return 0; |
443 | } | 443 | } |
444 | 444 | ||
@@ -544,11 +544,11 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
544 | * we don't have to do anything | 544 | * we don't have to do anything |
545 | */ | 545 | */ |
546 | if (memcmp(&cmp1, &cmp2, sizeof(cmp1)) == 0) { | 546 | if (memcmp(&cmp1, &cmp2, sizeof(cmp1)) == 0) { |
547 | btrfs_release_path(root, path); | 547 | btrfs_release_path(path); |
548 | goto out; | 548 | goto out; |
549 | } | 549 | } |
550 | } | 550 | } |
551 | btrfs_release_path(root, path); | 551 | btrfs_release_path(path); |
552 | 552 | ||
553 | saved_nbytes = inode_get_bytes(inode); | 553 | saved_nbytes = inode_get_bytes(inode); |
554 | /* drop any overlapping extents */ | 554 | /* drop any overlapping extents */ |
@@ -600,7 +600,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
600 | key->objectid, offset, &ins); | 600 | key->objectid, offset, &ins); |
601 | BUG_ON(ret); | 601 | BUG_ON(ret); |
602 | } | 602 | } |
603 | btrfs_release_path(root, path); | 603 | btrfs_release_path(path); |
604 | 604 | ||
605 | if (btrfs_file_extent_compression(eb, item)) { | 605 | if (btrfs_file_extent_compression(eb, item)) { |
606 | csum_start = ins.objectid; | 606 | csum_start = ins.objectid; |
@@ -629,7 +629,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
629 | kfree(sums); | 629 | kfree(sums); |
630 | } | 630 | } |
631 | } else { | 631 | } else { |
632 | btrfs_release_path(root, path); | 632 | btrfs_release_path(path); |
633 | } | 633 | } |
634 | } else if (found_type == BTRFS_FILE_EXTENT_INLINE) { | 634 | } else if (found_type == BTRFS_FILE_EXTENT_INLINE) { |
635 | /* inline extents are easy, we just overwrite them */ | 635 | /* inline extents are easy, we just overwrite them */ |
@@ -675,7 +675,7 @@ static noinline int drop_one_dir_item(struct btrfs_trans_handle *trans, | |||
675 | return -ENOMEM; | 675 | return -ENOMEM; |
676 | 676 | ||
677 | read_extent_buffer(leaf, name, (unsigned long)(di + 1), name_len); | 677 | read_extent_buffer(leaf, name, (unsigned long)(di + 1), name_len); |
678 | btrfs_release_path(root, path); | 678 | btrfs_release_path(path); |
679 | 679 | ||
680 | inode = read_one_inode(root, location.objectid); | 680 | inode = read_one_inode(root, location.objectid); |
681 | BUG_ON(!inode); | 681 | BUG_ON(!inode); |
@@ -713,7 +713,7 @@ static noinline int inode_in_dir(struct btrfs_root *root, | |||
713 | goto out; | 713 | goto out; |
714 | } else | 714 | } else |
715 | goto out; | 715 | goto out; |
716 | btrfs_release_path(root, path); | 716 | btrfs_release_path(path); |
717 | 717 | ||
718 | di = btrfs_lookup_dir_item(NULL, root, path, dirid, name, name_len, 0); | 718 | di = btrfs_lookup_dir_item(NULL, root, path, dirid, name, name_len, 0); |
719 | if (di && !IS_ERR(di)) { | 719 | if (di && !IS_ERR(di)) { |
@@ -724,7 +724,7 @@ static noinline int inode_in_dir(struct btrfs_root *root, | |||
724 | goto out; | 724 | goto out; |
725 | match = 1; | 725 | match = 1; |
726 | out: | 726 | out: |
727 | btrfs_release_path(root, path); | 727 | btrfs_release_path(path); |
728 | return match; | 728 | return match; |
729 | } | 729 | } |
730 | 730 | ||
@@ -884,7 +884,7 @@ again: | |||
884 | if (!backref_in_log(log, key, victim_name, | 884 | if (!backref_in_log(log, key, victim_name, |
885 | victim_name_len)) { | 885 | victim_name_len)) { |
886 | btrfs_inc_nlink(inode); | 886 | btrfs_inc_nlink(inode); |
887 | btrfs_release_path(root, path); | 887 | btrfs_release_path(path); |
888 | 888 | ||
889 | ret = btrfs_unlink_inode(trans, root, dir, | 889 | ret = btrfs_unlink_inode(trans, root, dir, |
890 | inode, victim_name, | 890 | inode, victim_name, |
@@ -901,7 +901,7 @@ again: | |||
901 | */ | 901 | */ |
902 | search_done = 1; | 902 | search_done = 1; |
903 | } | 903 | } |
904 | btrfs_release_path(root, path); | 904 | btrfs_release_path(path); |
905 | 905 | ||
906 | insert: | 906 | insert: |
907 | /* insert our name */ | 907 | /* insert our name */ |
@@ -922,7 +922,7 @@ out: | |||
922 | BUG_ON(ret); | 922 | BUG_ON(ret); |
923 | 923 | ||
924 | out_nowrite: | 924 | out_nowrite: |
925 | btrfs_release_path(root, path); | 925 | btrfs_release_path(path); |
926 | iput(dir); | 926 | iput(dir); |
927 | iput(inode); | 927 | iput(inode); |
928 | return 0; | 928 | return 0; |
@@ -1000,9 +1000,9 @@ static noinline int fixup_inode_link_count(struct btrfs_trans_handle *trans, | |||
1000 | if (key.offset == 0) | 1000 | if (key.offset == 0) |
1001 | break; | 1001 | break; |
1002 | key.offset--; | 1002 | key.offset--; |
1003 | btrfs_release_path(root, path); | 1003 | btrfs_release_path(path); |
1004 | } | 1004 | } |
1005 | btrfs_release_path(root, path); | 1005 | btrfs_release_path(path); |
1006 | if (nlink != inode->i_nlink) { | 1006 | if (nlink != inode->i_nlink) { |
1007 | inode->i_nlink = nlink; | 1007 | inode->i_nlink = nlink; |
1008 | btrfs_update_inode(trans, root, inode); | 1008 | btrfs_update_inode(trans, root, inode); |
@@ -1053,7 +1053,7 @@ static noinline int fixup_inode_link_counts(struct btrfs_trans_handle *trans, | |||
1053 | ret = btrfs_del_item(trans, root, path); | 1053 | ret = btrfs_del_item(trans, root, path); |
1054 | BUG_ON(ret); | 1054 | BUG_ON(ret); |
1055 | 1055 | ||
1056 | btrfs_release_path(root, path); | 1056 | btrfs_release_path(path); |
1057 | inode = read_one_inode(root, key.offset); | 1057 | inode = read_one_inode(root, key.offset); |
1058 | BUG_ON(!inode); | 1058 | BUG_ON(!inode); |
1059 | 1059 | ||
@@ -1069,7 +1069,7 @@ static noinline int fixup_inode_link_counts(struct btrfs_trans_handle *trans, | |||
1069 | */ | 1069 | */ |
1070 | key.offset = (u64)-1; | 1070 | key.offset = (u64)-1; |
1071 | } | 1071 | } |
1072 | btrfs_release_path(root, path); | 1072 | btrfs_release_path(path); |
1073 | return 0; | 1073 | return 0; |
1074 | } | 1074 | } |
1075 | 1075 | ||
@@ -1097,7 +1097,7 @@ static noinline int link_to_fixup_dir(struct btrfs_trans_handle *trans, | |||
1097 | 1097 | ||
1098 | ret = btrfs_insert_empty_item(trans, root, path, &key, 0); | 1098 | ret = btrfs_insert_empty_item(trans, root, path, &key, 0); |
1099 | 1099 | ||
1100 | btrfs_release_path(root, path); | 1100 | btrfs_release_path(path); |
1101 | if (ret == 0) { | 1101 | if (ret == 0) { |
1102 | btrfs_inc_nlink(inode); | 1102 | btrfs_inc_nlink(inode); |
1103 | btrfs_update_inode(trans, root, inode); | 1103 | btrfs_update_inode(trans, root, inode); |
@@ -1193,7 +1193,7 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans, | |||
1193 | exists = 1; | 1193 | exists = 1; |
1194 | else | 1194 | else |
1195 | exists = 0; | 1195 | exists = 0; |
1196 | btrfs_release_path(root, path); | 1196 | btrfs_release_path(path); |
1197 | 1197 | ||
1198 | if (key->type == BTRFS_DIR_ITEM_KEY) { | 1198 | if (key->type == BTRFS_DIR_ITEM_KEY) { |
1199 | dst_di = btrfs_lookup_dir_item(trans, root, path, key->objectid, | 1199 | dst_di = btrfs_lookup_dir_item(trans, root, path, key->objectid, |
@@ -1206,7 +1206,7 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans, | |||
1206 | } else { | 1206 | } else { |
1207 | BUG(); | 1207 | BUG(); |
1208 | } | 1208 | } |
1209 | if (!dst_di || IS_ERR(dst_di)) { | 1209 | if (IS_ERR_OR_NULL(dst_di)) { |
1210 | /* we need a sequence number to insert, so we only | 1210 | /* we need a sequence number to insert, so we only |
1211 | * do inserts for the BTRFS_DIR_INDEX_KEY types | 1211 | * do inserts for the BTRFS_DIR_INDEX_KEY types |
1212 | */ | 1212 | */ |
@@ -1237,13 +1237,13 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans, | |||
1237 | if (key->type == BTRFS_DIR_INDEX_KEY) | 1237 | if (key->type == BTRFS_DIR_INDEX_KEY) |
1238 | goto insert; | 1238 | goto insert; |
1239 | out: | 1239 | out: |
1240 | btrfs_release_path(root, path); | 1240 | btrfs_release_path(path); |
1241 | kfree(name); | 1241 | kfree(name); |
1242 | iput(dir); | 1242 | iput(dir); |
1243 | return 0; | 1243 | return 0; |
1244 | 1244 | ||
1245 | insert: | 1245 | insert: |
1246 | btrfs_release_path(root, path); | 1246 | btrfs_release_path(path); |
1247 | ret = insert_one_name(trans, root, path, key->objectid, key->offset, | 1247 | ret = insert_one_name(trans, root, path, key->objectid, key->offset, |
1248 | name, name_len, log_type, &log_key); | 1248 | name, name_len, log_type, &log_key); |
1249 | 1249 | ||
@@ -1364,7 +1364,7 @@ next: | |||
1364 | *end_ret = found_end; | 1364 | *end_ret = found_end; |
1365 | ret = 0; | 1365 | ret = 0; |
1366 | out: | 1366 | out: |
1367 | btrfs_release_path(root, path); | 1367 | btrfs_release_path(path); |
1368 | return ret; | 1368 | return ret; |
1369 | } | 1369 | } |
1370 | 1370 | ||
@@ -1427,10 +1427,10 @@ again: | |||
1427 | dir_key->offset, | 1427 | dir_key->offset, |
1428 | name, name_len, 0); | 1428 | name, name_len, 0); |
1429 | } | 1429 | } |
1430 | if (!log_di || IS_ERR(log_di)) { | 1430 | if (IS_ERR_OR_NULL(log_di)) { |
1431 | btrfs_dir_item_key_to_cpu(eb, di, &location); | 1431 | btrfs_dir_item_key_to_cpu(eb, di, &location); |
1432 | btrfs_release_path(root, path); | 1432 | btrfs_release_path(path); |
1433 | btrfs_release_path(log, log_path); | 1433 | btrfs_release_path(log_path); |
1434 | inode = read_one_inode(root, location.objectid); | 1434 | inode = read_one_inode(root, location.objectid); |
1435 | BUG_ON(!inode); | 1435 | BUG_ON(!inode); |
1436 | 1436 | ||
@@ -1454,7 +1454,7 @@ again: | |||
1454 | ret = 0; | 1454 | ret = 0; |
1455 | goto out; | 1455 | goto out; |
1456 | } | 1456 | } |
1457 | btrfs_release_path(log, log_path); | 1457 | btrfs_release_path(log_path); |
1458 | kfree(name); | 1458 | kfree(name); |
1459 | 1459 | ||
1460 | ptr = (unsigned long)(di + 1); | 1460 | ptr = (unsigned long)(di + 1); |
@@ -1462,8 +1462,8 @@ again: | |||
1462 | } | 1462 | } |
1463 | ret = 0; | 1463 | ret = 0; |
1464 | out: | 1464 | out: |
1465 | btrfs_release_path(root, path); | 1465 | btrfs_release_path(path); |
1466 | btrfs_release_path(log, log_path); | 1466 | btrfs_release_path(log_path); |
1467 | return ret; | 1467 | return ret; |
1468 | } | 1468 | } |
1469 | 1469 | ||
@@ -1551,7 +1551,7 @@ again: | |||
1551 | break; | 1551 | break; |
1552 | dir_key.offset = found_key.offset + 1; | 1552 | dir_key.offset = found_key.offset + 1; |
1553 | } | 1553 | } |
1554 | btrfs_release_path(root, path); | 1554 | btrfs_release_path(path); |
1555 | if (range_end == (u64)-1) | 1555 | if (range_end == (u64)-1) |
1556 | break; | 1556 | break; |
1557 | range_start = range_end + 1; | 1557 | range_start = range_end + 1; |
@@ -1562,11 +1562,11 @@ next_type: | |||
1562 | if (key_type == BTRFS_DIR_LOG_ITEM_KEY) { | 1562 | if (key_type == BTRFS_DIR_LOG_ITEM_KEY) { |
1563 | key_type = BTRFS_DIR_LOG_INDEX_KEY; | 1563 | key_type = BTRFS_DIR_LOG_INDEX_KEY; |
1564 | dir_key.type = BTRFS_DIR_INDEX_KEY; | 1564 | dir_key.type = BTRFS_DIR_INDEX_KEY; |
1565 | btrfs_release_path(root, path); | 1565 | btrfs_release_path(path); |
1566 | goto again; | 1566 | goto again; |
1567 | } | 1567 | } |
1568 | out: | 1568 | out: |
1569 | btrfs_release_path(root, path); | 1569 | btrfs_release_path(path); |
1570 | btrfs_free_path(log_path); | 1570 | btrfs_free_path(log_path); |
1571 | iput(dir); | 1571 | iput(dir); |
1572 | return ret; | 1572 | return ret; |
@@ -2227,7 +2227,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, | |||
2227 | bytes_del += name_len; | 2227 | bytes_del += name_len; |
2228 | BUG_ON(ret); | 2228 | BUG_ON(ret); |
2229 | } | 2229 | } |
2230 | btrfs_release_path(log, path); | 2230 | btrfs_release_path(path); |
2231 | di = btrfs_lookup_dir_index_item(trans, log, path, dir_ino, | 2231 | di = btrfs_lookup_dir_index_item(trans, log, path, dir_ino, |
2232 | index, name, name_len, -1); | 2232 | index, name, name_len, -1); |
2233 | if (IS_ERR(di)) { | 2233 | if (IS_ERR(di)) { |
@@ -2249,7 +2249,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, | |||
2249 | key.objectid = dir_ino; | 2249 | key.objectid = dir_ino; |
2250 | key.offset = 0; | 2250 | key.offset = 0; |
2251 | key.type = BTRFS_INODE_ITEM_KEY; | 2251 | key.type = BTRFS_INODE_ITEM_KEY; |
2252 | btrfs_release_path(log, path); | 2252 | btrfs_release_path(path); |
2253 | 2253 | ||
2254 | ret = btrfs_search_slot(trans, log, &key, path, 0, 1); | 2254 | ret = btrfs_search_slot(trans, log, &key, path, 0, 1); |
2255 | if (ret < 0) { | 2255 | if (ret < 0) { |
@@ -2271,7 +2271,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, | |||
2271 | btrfs_mark_buffer_dirty(path->nodes[0]); | 2271 | btrfs_mark_buffer_dirty(path->nodes[0]); |
2272 | } else | 2272 | } else |
2273 | ret = 0; | 2273 | ret = 0; |
2274 | btrfs_release_path(log, path); | 2274 | btrfs_release_path(path); |
2275 | } | 2275 | } |
2276 | fail: | 2276 | fail: |
2277 | btrfs_free_path(path); | 2277 | btrfs_free_path(path); |
@@ -2346,7 +2346,7 @@ static noinline int insert_dir_log_key(struct btrfs_trans_handle *trans, | |||
2346 | struct btrfs_dir_log_item); | 2346 | struct btrfs_dir_log_item); |
2347 | btrfs_set_dir_log_end(path->nodes[0], item, last_offset); | 2347 | btrfs_set_dir_log_end(path->nodes[0], item, last_offset); |
2348 | btrfs_mark_buffer_dirty(path->nodes[0]); | 2348 | btrfs_mark_buffer_dirty(path->nodes[0]); |
2349 | btrfs_release_path(log, path); | 2349 | btrfs_release_path(path); |
2350 | return 0; | 2350 | return 0; |
2351 | } | 2351 | } |
2352 | 2352 | ||
@@ -2395,10 +2395,10 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, | |||
2395 | min_key.objectid = ino; | 2395 | min_key.objectid = ino; |
2396 | min_key.type = key_type; | 2396 | min_key.type = key_type; |
2397 | min_key.offset = (u64)-1; | 2397 | min_key.offset = (u64)-1; |
2398 | btrfs_release_path(root, path); | 2398 | btrfs_release_path(path); |
2399 | ret = btrfs_search_slot(NULL, root, &min_key, path, 0, 0); | 2399 | ret = btrfs_search_slot(NULL, root, &min_key, path, 0, 0); |
2400 | if (ret < 0) { | 2400 | if (ret < 0) { |
2401 | btrfs_release_path(root, path); | 2401 | btrfs_release_path(path); |
2402 | return ret; | 2402 | return ret; |
2403 | } | 2403 | } |
2404 | ret = btrfs_previous_item(root, path, ino, key_type); | 2404 | ret = btrfs_previous_item(root, path, ino, key_type); |
@@ -2434,7 +2434,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, | |||
2434 | } | 2434 | } |
2435 | } | 2435 | } |
2436 | } | 2436 | } |
2437 | btrfs_release_path(root, path); | 2437 | btrfs_release_path(path); |
2438 | 2438 | ||
2439 | /* find the first key from this transaction again */ | 2439 | /* find the first key from this transaction again */ |
2440 | ret = btrfs_search_slot(NULL, root, &min_key, path, 0, 0); | 2440 | ret = btrfs_search_slot(NULL, root, &min_key, path, 0, 0); |
@@ -2491,8 +2491,8 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, | |||
2491 | } | 2491 | } |
2492 | } | 2492 | } |
2493 | done: | 2493 | done: |
2494 | btrfs_release_path(root, path); | 2494 | btrfs_release_path(path); |
2495 | btrfs_release_path(log, dst_path); | 2495 | btrfs_release_path(dst_path); |
2496 | 2496 | ||
2497 | if (err == 0) { | 2497 | if (err == 0) { |
2498 | *last_offset_ret = last_offset; | 2498 | *last_offset_ret = last_offset; |
@@ -2588,9 +2588,9 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans, | |||
2588 | 2588 | ||
2589 | ret = btrfs_del_item(trans, log, path); | 2589 | ret = btrfs_del_item(trans, log, path); |
2590 | BUG_ON(ret); | 2590 | BUG_ON(ret); |
2591 | btrfs_release_path(log, path); | 2591 | btrfs_release_path(path); |
2592 | } | 2592 | } |
2593 | btrfs_release_path(log, path); | 2593 | btrfs_release_path(path); |
2594 | return ret; | 2594 | return ret; |
2595 | } | 2595 | } |
2596 | 2596 | ||
@@ -2696,7 +2696,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans, | |||
2696 | } | 2696 | } |
2697 | 2697 | ||
2698 | btrfs_mark_buffer_dirty(dst_path->nodes[0]); | 2698 | btrfs_mark_buffer_dirty(dst_path->nodes[0]); |
2699 | btrfs_release_path(log, dst_path); | 2699 | btrfs_release_path(dst_path); |
2700 | kfree(ins_data); | 2700 | kfree(ins_data); |
2701 | 2701 | ||
2702 | /* | 2702 | /* |
@@ -2852,7 +2852,7 @@ next_slot: | |||
2852 | } | 2852 | } |
2853 | ins_nr = 0; | 2853 | ins_nr = 0; |
2854 | } | 2854 | } |
2855 | btrfs_release_path(root, path); | 2855 | btrfs_release_path(path); |
2856 | 2856 | ||
2857 | if (min_key.offset < (u64)-1) | 2857 | if (min_key.offset < (u64)-1) |
2858 | min_key.offset++; | 2858 | min_key.offset++; |
@@ -2875,8 +2875,8 @@ next_slot: | |||
2875 | } | 2875 | } |
2876 | WARN_ON(ins_nr); | 2876 | WARN_ON(ins_nr); |
2877 | if (inode_only == LOG_INODE_ALL && S_ISDIR(inode->i_mode)) { | 2877 | if (inode_only == LOG_INODE_ALL && S_ISDIR(inode->i_mode)) { |
2878 | btrfs_release_path(root, path); | 2878 | btrfs_release_path(path); |
2879 | btrfs_release_path(log, dst_path); | 2879 | btrfs_release_path(dst_path); |
2880 | ret = log_directory_changes(trans, root, inode, path, dst_path); | 2880 | ret = log_directory_changes(trans, root, inode, path, dst_path); |
2881 | if (ret) { | 2881 | if (ret) { |
2882 | err = ret; | 2882 | err = ret; |
@@ -3143,7 +3143,7 @@ again: | |||
3143 | } | 3143 | } |
3144 | btrfs_item_key_to_cpu(path->nodes[0], &found_key, | 3144 | btrfs_item_key_to_cpu(path->nodes[0], &found_key, |
3145 | path->slots[0]); | 3145 | path->slots[0]); |
3146 | btrfs_release_path(log_root_tree, path); | 3146 | btrfs_release_path(path); |
3147 | if (found_key.objectid != BTRFS_TREE_LOG_OBJECTID) | 3147 | if (found_key.objectid != BTRFS_TREE_LOG_OBJECTID) |
3148 | break; | 3148 | break; |
3149 | 3149 | ||
@@ -3178,7 +3178,7 @@ again: | |||
3178 | if (found_key.offset == 0) | 3178 | if (found_key.offset == 0) |
3179 | break; | 3179 | break; |
3180 | } | 3180 | } |
3181 | btrfs_release_path(log_root_tree, path); | 3181 | btrfs_release_path(path); |
3182 | 3182 | ||
3183 | /* step one is to pin it all, step two is to replay just inodes */ | 3183 | /* step one is to pin it all, step two is to replay just inodes */ |
3184 | if (wc.pin) { | 3184 | if (wc.pin) { |
diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h index 3dfae84c8cc8..2270ac58d746 100644 --- a/fs/btrfs/tree-log.h +++ b/fs/btrfs/tree-log.h | |||
@@ -38,7 +38,6 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, | |||
38 | struct btrfs_root *root, | 38 | struct btrfs_root *root, |
39 | const char *name, int name_len, | 39 | const char *name, int name_len, |
40 | struct inode *inode, u64 dirid); | 40 | struct inode *inode, u64 dirid); |
41 | int btrfs_join_running_log_trans(struct btrfs_root *root); | ||
42 | int btrfs_end_log_trans(struct btrfs_root *root); | 41 | int btrfs_end_log_trans(struct btrfs_root *root); |
43 | int btrfs_pin_log_trans(struct btrfs_root *root); | 42 | int btrfs_pin_log_trans(struct btrfs_root *root); |
44 | int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, | 43 | int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index c7367ae5a3e6..cd0b31a9ba3d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -44,16 +44,6 @@ static int btrfs_relocate_sys_chunks(struct btrfs_root *root); | |||
44 | static DEFINE_MUTEX(uuid_mutex); | 44 | static DEFINE_MUTEX(uuid_mutex); |
45 | static LIST_HEAD(fs_uuids); | 45 | static LIST_HEAD(fs_uuids); |
46 | 46 | ||
47 | void btrfs_lock_volumes(void) | ||
48 | { | ||
49 | mutex_lock(&uuid_mutex); | ||
50 | } | ||
51 | |||
52 | void btrfs_unlock_volumes(void) | ||
53 | { | ||
54 | mutex_unlock(&uuid_mutex); | ||
55 | } | ||
56 | |||
57 | static void lock_chunks(struct btrfs_root *root) | 47 | static void lock_chunks(struct btrfs_root *root) |
58 | { | 48 | { |
59 | mutex_lock(&root->fs_info->chunk_mutex); | 49 | mutex_lock(&root->fs_info->chunk_mutex); |
@@ -1475,7 +1465,7 @@ next_slot: | |||
1475 | goto error; | 1465 | goto error; |
1476 | leaf = path->nodes[0]; | 1466 | leaf = path->nodes[0]; |
1477 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); | 1467 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); |
1478 | btrfs_release_path(root, path); | 1468 | btrfs_release_path(path); |
1479 | continue; | 1469 | continue; |
1480 | } | 1470 | } |
1481 | 1471 | ||
@@ -1947,7 +1937,7 @@ again: | |||
1947 | chunk = btrfs_item_ptr(leaf, path->slots[0], | 1937 | chunk = btrfs_item_ptr(leaf, path->slots[0], |
1948 | struct btrfs_chunk); | 1938 | struct btrfs_chunk); |
1949 | chunk_type = btrfs_chunk_type(leaf, chunk); | 1939 | chunk_type = btrfs_chunk_type(leaf, chunk); |
1950 | btrfs_release_path(chunk_root, path); | 1940 | btrfs_release_path(path); |
1951 | 1941 | ||
1952 | if (chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) { | 1942 | if (chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) { |
1953 | ret = btrfs_relocate_chunk(chunk_root, chunk_tree, | 1943 | ret = btrfs_relocate_chunk(chunk_root, chunk_tree, |
@@ -2065,7 +2055,7 @@ int btrfs_balance(struct btrfs_root *dev_root) | |||
2065 | if (found_key.offset == 0) | 2055 | if (found_key.offset == 0) |
2066 | break; | 2056 | break; |
2067 | 2057 | ||
2068 | btrfs_release_path(chunk_root, path); | 2058 | btrfs_release_path(path); |
2069 | ret = btrfs_relocate_chunk(chunk_root, | 2059 | ret = btrfs_relocate_chunk(chunk_root, |
2070 | chunk_root->root_key.objectid, | 2060 | chunk_root->root_key.objectid, |
2071 | found_key.objectid, | 2061 | found_key.objectid, |
@@ -2137,7 +2127,7 @@ again: | |||
2137 | goto done; | 2127 | goto done; |
2138 | if (ret) { | 2128 | if (ret) { |
2139 | ret = 0; | 2129 | ret = 0; |
2140 | btrfs_release_path(root, path); | 2130 | btrfs_release_path(path); |
2141 | break; | 2131 | break; |
2142 | } | 2132 | } |
2143 | 2133 | ||
@@ -2146,7 +2136,7 @@ again: | |||
2146 | btrfs_item_key_to_cpu(l, &key, path->slots[0]); | 2136 | btrfs_item_key_to_cpu(l, &key, path->slots[0]); |
2147 | 2137 | ||
2148 | if (key.objectid != device->devid) { | 2138 | if (key.objectid != device->devid) { |
2149 | btrfs_release_path(root, path); | 2139 | btrfs_release_path(path); |
2150 | break; | 2140 | break; |
2151 | } | 2141 | } |
2152 | 2142 | ||
@@ -2154,14 +2144,14 @@ again: | |||
2154 | length = btrfs_dev_extent_length(l, dev_extent); | 2144 | length = btrfs_dev_extent_length(l, dev_extent); |
2155 | 2145 | ||
2156 | if (key.offset + length <= new_size) { | 2146 | if (key.offset + length <= new_size) { |
2157 | btrfs_release_path(root, path); | 2147 | btrfs_release_path(path); |
2158 | break; | 2148 | break; |
2159 | } | 2149 | } |
2160 | 2150 | ||
2161 | chunk_tree = btrfs_dev_extent_chunk_tree(l, dev_extent); | 2151 | chunk_tree = btrfs_dev_extent_chunk_tree(l, dev_extent); |
2162 | chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent); | 2152 | chunk_objectid = btrfs_dev_extent_chunk_objectid(l, dev_extent); |
2163 | chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent); | 2153 | chunk_offset = btrfs_dev_extent_chunk_offset(l, dev_extent); |
2164 | btrfs_release_path(root, path); | 2154 | btrfs_release_path(path); |
2165 | 2155 | ||
2166 | ret = btrfs_relocate_chunk(root, chunk_tree, chunk_objectid, | 2156 | ret = btrfs_relocate_chunk(root, chunk_tree, chunk_objectid, |
2167 | chunk_offset); | 2157 | chunk_offset); |
@@ -2609,7 +2599,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, | |||
2609 | 2599 | ||
2610 | trace_btrfs_chunk_alloc(info->chunk_root, map, start, *num_bytes); | 2600 | trace_btrfs_chunk_alloc(info->chunk_root, map, start, *num_bytes); |
2611 | 2601 | ||
2612 | em = alloc_extent_map(GFP_NOFS); | 2602 | em = alloc_extent_map(); |
2613 | if (!em) { | 2603 | if (!em) { |
2614 | ret = -ENOMEM; | 2604 | ret = -ENOMEM; |
2615 | goto error; | 2605 | goto error; |
@@ -2849,7 +2839,7 @@ int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset) | |||
2849 | 2839 | ||
2850 | void btrfs_mapping_init(struct btrfs_mapping_tree *tree) | 2840 | void btrfs_mapping_init(struct btrfs_mapping_tree *tree) |
2851 | { | 2841 | { |
2852 | extent_map_tree_init(&tree->map_tree, GFP_NOFS); | 2842 | extent_map_tree_init(&tree->map_tree); |
2853 | } | 2843 | } |
2854 | 2844 | ||
2855 | void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree) | 2845 | void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree) |
@@ -3499,7 +3489,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key, | |||
3499 | free_extent_map(em); | 3489 | free_extent_map(em); |
3500 | } | 3490 | } |
3501 | 3491 | ||
3502 | em = alloc_extent_map(GFP_NOFS); | 3492 | em = alloc_extent_map(); |
3503 | if (!em) | 3493 | if (!em) |
3504 | return -ENOMEM; | 3494 | return -ENOMEM; |
3505 | num_stripes = btrfs_chunk_num_stripes(leaf, chunk); | 3495 | num_stripes = btrfs_chunk_num_stripes(leaf, chunk); |
@@ -3688,15 +3678,6 @@ static int read_one_dev(struct btrfs_root *root, | |||
3688 | return ret; | 3678 | return ret; |
3689 | } | 3679 | } |
3690 | 3680 | ||
3691 | int btrfs_read_super_device(struct btrfs_root *root, struct extent_buffer *buf) | ||
3692 | { | ||
3693 | struct btrfs_dev_item *dev_item; | ||
3694 | |||
3695 | dev_item = (struct btrfs_dev_item *)offsetof(struct btrfs_super_block, | ||
3696 | dev_item); | ||
3697 | return read_one_dev(root, buf, dev_item); | ||
3698 | } | ||
3699 | |||
3700 | int btrfs_read_sys_array(struct btrfs_root *root) | 3681 | int btrfs_read_sys_array(struct btrfs_root *root) |
3701 | { | 3682 | { |
3702 | struct btrfs_super_block *super_copy = &root->fs_info->super_copy; | 3683 | struct btrfs_super_block *super_copy = &root->fs_info->super_copy; |
@@ -3813,7 +3794,7 @@ again: | |||
3813 | } | 3794 | } |
3814 | if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { | 3795 | if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { |
3815 | key.objectid = 0; | 3796 | key.objectid = 0; |
3816 | btrfs_release_path(root, path); | 3797 | btrfs_release_path(path); |
3817 | goto again; | 3798 | goto again; |
3818 | } | 3799 | } |
3819 | ret = 0; | 3800 | ret = 0; |
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index cc2eadaf7a27..5669ae8ea1c9 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h | |||
@@ -196,7 +196,6 @@ void btrfs_mapping_init(struct btrfs_mapping_tree *tree); | |||
196 | void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); | 196 | void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); |
197 | int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio, | 197 | int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio, |
198 | int mirror_num, int async_submit); | 198 | int mirror_num, int async_submit); |
199 | int btrfs_read_super_device(struct btrfs_root *root, struct extent_buffer *buf); | ||
200 | int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, | 199 | int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, |
201 | fmode_t flags, void *holder); | 200 | fmode_t flags, void *holder); |
202 | int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, | 201 | int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, |
@@ -209,8 +208,6 @@ int btrfs_add_device(struct btrfs_trans_handle *trans, | |||
209 | int btrfs_rm_device(struct btrfs_root *root, char *device_path); | 208 | int btrfs_rm_device(struct btrfs_root *root, char *device_path); |
210 | int btrfs_cleanup_fs_uuids(void); | 209 | int btrfs_cleanup_fs_uuids(void); |
211 | int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len); | 210 | int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len); |
212 | int btrfs_unplug_page(struct btrfs_mapping_tree *map_tree, | ||
213 | u64 logical, struct page *page); | ||
214 | int btrfs_grow_device(struct btrfs_trans_handle *trans, | 211 | int btrfs_grow_device(struct btrfs_trans_handle *trans, |
215 | struct btrfs_device *device, u64 new_size); | 212 | struct btrfs_device *device, u64 new_size); |
216 | struct btrfs_device *btrfs_find_device(struct btrfs_root *root, u64 devid, | 213 | struct btrfs_device *btrfs_find_device(struct btrfs_root *root, u64 devid, |
@@ -218,8 +215,6 @@ struct btrfs_device *btrfs_find_device(struct btrfs_root *root, u64 devid, | |||
218 | int btrfs_shrink_device(struct btrfs_device *device, u64 new_size); | 215 | int btrfs_shrink_device(struct btrfs_device *device, u64 new_size); |
219 | int btrfs_init_new_device(struct btrfs_root *root, char *path); | 216 | int btrfs_init_new_device(struct btrfs_root *root, char *path); |
220 | int btrfs_balance(struct btrfs_root *dev_root); | 217 | int btrfs_balance(struct btrfs_root *dev_root); |
221 | void btrfs_unlock_volumes(void); | ||
222 | void btrfs_lock_volumes(void); | ||
223 | int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); | 218 | int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); |
224 | int find_free_dev_extent(struct btrfs_trans_handle *trans, | 219 | int find_free_dev_extent(struct btrfs_trans_handle *trans, |
225 | struct btrfs_device *device, u64 num_bytes, | 220 | struct btrfs_device *device, u64 num_bytes, |
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c index 4e5a32173c42..f3107e4b4d56 100644 --- a/fs/btrfs/xattr.c +++ b/fs/btrfs/xattr.c | |||
@@ -120,13 +120,13 @@ static int do_setxattr(struct btrfs_trans_handle *trans, | |||
120 | 120 | ||
121 | ret = btrfs_delete_one_dir_name(trans, root, path, di); | 121 | ret = btrfs_delete_one_dir_name(trans, root, path, di); |
122 | BUG_ON(ret); | 122 | BUG_ON(ret); |
123 | btrfs_release_path(root, path); | 123 | btrfs_release_path(path); |
124 | 124 | ||
125 | /* if we don't have a value then we are removing the xattr */ | 125 | /* if we don't have a value then we are removing the xattr */ |
126 | if (!value) | 126 | if (!value) |
127 | goto out; | 127 | goto out; |
128 | } else { | 128 | } else { |
129 | btrfs_release_path(root, path); | 129 | btrfs_release_path(path); |
130 | 130 | ||
131 | if (flags & XATTR_REPLACE) { | 131 | if (flags & XATTR_REPLACE) { |
132 | /* we couldn't find the attr to replace */ | 132 | /* we couldn't find the attr to replace */ |