diff options
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 269 |
1 files changed, 137 insertions, 132 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8072cfa8a3b1..81ea55314b1f 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <linux/workqueue.h> | 26 | #include <linux/workqueue.h> |
27 | #include <linux/kthread.h> | 27 | #include <linux/kthread.h> |
28 | #include <linux/freezer.h> | 28 | #include <linux/freezer.h> |
29 | #include <linux/crc32c.h> | ||
30 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
31 | #include <linux/migrate.h> | 30 | #include <linux/migrate.h> |
32 | #include <linux/ratelimit.h> | 31 | #include <linux/ratelimit.h> |
@@ -35,6 +34,7 @@ | |||
35 | #include <asm/unaligned.h> | 34 | #include <asm/unaligned.h> |
36 | #include "ctree.h" | 35 | #include "ctree.h" |
37 | #include "disk-io.h" | 36 | #include "disk-io.h" |
37 | #include "hash.h" | ||
38 | #include "transaction.h" | 38 | #include "transaction.h" |
39 | #include "btrfs_inode.h" | 39 | #include "btrfs_inode.h" |
40 | #include "volumes.h" | 40 | #include "volumes.h" |
@@ -48,6 +48,7 @@ | |||
48 | #include "rcu-string.h" | 48 | #include "rcu-string.h" |
49 | #include "dev-replace.h" | 49 | #include "dev-replace.h" |
50 | #include "raid56.h" | 50 | #include "raid56.h" |
51 | #include "sysfs.h" | ||
51 | 52 | ||
52 | #ifdef CONFIG_X86 | 53 | #ifdef CONFIG_X86 |
53 | #include <asm/cpufeature.h> | 54 | #include <asm/cpufeature.h> |
@@ -243,7 +244,7 @@ out: | |||
243 | 244 | ||
244 | u32 btrfs_csum_data(char *data, u32 seed, size_t len) | 245 | u32 btrfs_csum_data(char *data, u32 seed, size_t len) |
245 | { | 246 | { |
246 | return crc32c(seed, data, len); | 247 | return btrfs_crc32c(seed, data, len); |
247 | } | 248 | } |
248 | 249 | ||
249 | void btrfs_csum_final(u32 crc, char *result) | 250 | void btrfs_csum_final(u32 crc, char *result) |
@@ -299,11 +300,11 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, | |||
299 | memcpy(&found, result, csum_size); | 300 | memcpy(&found, result, csum_size); |
300 | 301 | ||
301 | read_extent_buffer(buf, &val, 0, csum_size); | 302 | read_extent_buffer(buf, &val, 0, csum_size); |
302 | printk_ratelimited(KERN_INFO "btrfs: %s checksum verify " | 303 | printk_ratelimited(KERN_INFO |
303 | "failed on %llu wanted %X found %X " | 304 | "BTRFS: %s checksum verify failed on %llu wanted %X found %X " |
304 | "level %d\n", | 305 | "level %d\n", |
305 | root->fs_info->sb->s_id, buf->start, | 306 | root->fs_info->sb->s_id, buf->start, |
306 | val, found, btrfs_header_level(buf)); | 307 | val, found, btrfs_header_level(buf)); |
307 | if (result != (char *)&inline_result) | 308 | if (result != (char *)&inline_result) |
308 | kfree(result); | 309 | kfree(result); |
309 | return 1; | 310 | return 1; |
@@ -382,13 +383,14 @@ static int btrfs_check_super_csum(char *raw_disk_sb) | |||
382 | ret = 1; | 383 | ret = 1; |
383 | 384 | ||
384 | if (ret && btrfs_super_generation(disk_sb) < 10) { | 385 | if (ret && btrfs_super_generation(disk_sb) < 10) { |
385 | printk(KERN_WARNING "btrfs: super block crcs don't match, older mkfs detected\n"); | 386 | printk(KERN_WARNING |
387 | "BTRFS: super block crcs don't match, older mkfs detected\n"); | ||
386 | ret = 0; | 388 | ret = 0; |
387 | } | 389 | } |
388 | } | 390 | } |
389 | 391 | ||
390 | if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) { | 392 | if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) { |
391 | printk(KERN_ERR "btrfs: unsupported checksum algorithm %u\n", | 393 | printk(KERN_ERR "BTRFS: unsupported checksum algorithm %u\n", |
392 | csum_type); | 394 | csum_type); |
393 | ret = 1; | 395 | ret = 1; |
394 | } | 396 | } |
@@ -464,13 +466,10 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root, | |||
464 | 466 | ||
465 | static int csum_dirty_buffer(struct btrfs_root *root, struct page *page) | 467 | static int csum_dirty_buffer(struct btrfs_root *root, struct page *page) |
466 | { | 468 | { |
467 | struct extent_io_tree *tree; | ||
468 | u64 start = page_offset(page); | 469 | u64 start = page_offset(page); |
469 | u64 found_start; | 470 | u64 found_start; |
470 | struct extent_buffer *eb; | 471 | struct extent_buffer *eb; |
471 | 472 | ||
472 | tree = &BTRFS_I(page->mapping->host)->io_tree; | ||
473 | |||
474 | eb = (struct extent_buffer *)page->private; | 473 | eb = (struct extent_buffer *)page->private; |
475 | if (page != eb->pages[0]) | 474 | if (page != eb->pages[0]) |
476 | return 0; | 475 | return 0; |
@@ -500,8 +499,8 @@ static int check_tree_block_fsid(struct btrfs_root *root, | |||
500 | } | 499 | } |
501 | 500 | ||
502 | #define CORRUPT(reason, eb, root, slot) \ | 501 | #define CORRUPT(reason, eb, root, slot) \ |
503 | printk(KERN_CRIT "btrfs: corrupt leaf, %s: block=%llu," \ | 502 | btrfs_crit(root->fs_info, "corrupt leaf, %s: block=%llu," \ |
504 | "root=%llu, slot=%d\n", reason, \ | 503 | "root=%llu, slot=%d", reason, \ |
505 | btrfs_header_bytenr(eb), root->objectid, slot) | 504 | btrfs_header_bytenr(eb), root->objectid, slot) |
506 | 505 | ||
507 | static noinline int check_leaf(struct btrfs_root *root, | 506 | static noinline int check_leaf(struct btrfs_root *root, |
@@ -569,7 +568,6 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, | |||
569 | u64 phy_offset, struct page *page, | 568 | u64 phy_offset, struct page *page, |
570 | u64 start, u64 end, int mirror) | 569 | u64 start, u64 end, int mirror) |
571 | { | 570 | { |
572 | struct extent_io_tree *tree; | ||
573 | u64 found_start; | 571 | u64 found_start; |
574 | int found_level; | 572 | int found_level; |
575 | struct extent_buffer *eb; | 573 | struct extent_buffer *eb; |
@@ -580,7 +578,6 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, | |||
580 | if (!page->private) | 578 | if (!page->private) |
581 | goto out; | 579 | goto out; |
582 | 580 | ||
583 | tree = &BTRFS_I(page->mapping->host)->io_tree; | ||
584 | eb = (struct extent_buffer *)page->private; | 581 | eb = (struct extent_buffer *)page->private; |
585 | 582 | ||
586 | /* the pending IO might have been the only thing that kept this buffer | 583 | /* the pending IO might have been the only thing that kept this buffer |
@@ -600,21 +597,21 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, | |||
600 | 597 | ||
601 | found_start = btrfs_header_bytenr(eb); | 598 | found_start = btrfs_header_bytenr(eb); |
602 | if (found_start != eb->start) { | 599 | if (found_start != eb->start) { |
603 | printk_ratelimited(KERN_INFO "btrfs bad tree block start " | 600 | printk_ratelimited(KERN_INFO "BTRFS: bad tree block start " |
604 | "%llu %llu\n", | 601 | "%llu %llu\n", |
605 | found_start, eb->start); | 602 | found_start, eb->start); |
606 | ret = -EIO; | 603 | ret = -EIO; |
607 | goto err; | 604 | goto err; |
608 | } | 605 | } |
609 | if (check_tree_block_fsid(root, eb)) { | 606 | if (check_tree_block_fsid(root, eb)) { |
610 | printk_ratelimited(KERN_INFO "btrfs bad fsid on block %llu\n", | 607 | printk_ratelimited(KERN_INFO "BTRFS: bad fsid on block %llu\n", |
611 | eb->start); | 608 | eb->start); |
612 | ret = -EIO; | 609 | ret = -EIO; |
613 | goto err; | 610 | goto err; |
614 | } | 611 | } |
615 | found_level = btrfs_header_level(eb); | 612 | found_level = btrfs_header_level(eb); |
616 | if (found_level >= BTRFS_MAX_LEVEL) { | 613 | if (found_level >= BTRFS_MAX_LEVEL) { |
617 | btrfs_info(root->fs_info, "bad tree block level %d\n", | 614 | btrfs_info(root->fs_info, "bad tree block level %d", |
618 | (int)btrfs_header_level(eb)); | 615 | (int)btrfs_header_level(eb)); |
619 | ret = -EIO; | 616 | ret = -EIO; |
620 | goto err; | 617 | goto err; |
@@ -842,20 +839,17 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, | |||
842 | 839 | ||
843 | static int btree_csum_one_bio(struct bio *bio) | 840 | static int btree_csum_one_bio(struct bio *bio) |
844 | { | 841 | { |
845 | struct bio_vec *bvec = bio->bi_io_vec; | 842 | struct bio_vec *bvec; |
846 | int bio_index = 0; | ||
847 | struct btrfs_root *root; | 843 | struct btrfs_root *root; |
848 | int ret = 0; | 844 | int i, ret = 0; |
849 | 845 | ||
850 | WARN_ON(bio->bi_vcnt <= 0); | 846 | bio_for_each_segment_all(bvec, bio, i) { |
851 | while (bio_index < bio->bi_vcnt) { | ||
852 | root = BTRFS_I(bvec->bv_page->mapping->host)->root; | 847 | root = BTRFS_I(bvec->bv_page->mapping->host)->root; |
853 | ret = csum_dirty_buffer(root, bvec->bv_page); | 848 | ret = csum_dirty_buffer(root, bvec->bv_page); |
854 | if (ret) | 849 | if (ret) |
855 | break; | 850 | break; |
856 | bio_index++; | ||
857 | bvec++; | ||
858 | } | 851 | } |
852 | |||
859 | return ret; | 853 | return ret; |
860 | } | 854 | } |
861 | 855 | ||
@@ -967,11 +961,9 @@ static int btree_migratepage(struct address_space *mapping, | |||
967 | static int btree_writepages(struct address_space *mapping, | 961 | static int btree_writepages(struct address_space *mapping, |
968 | struct writeback_control *wbc) | 962 | struct writeback_control *wbc) |
969 | { | 963 | { |
970 | struct extent_io_tree *tree; | ||
971 | struct btrfs_fs_info *fs_info; | 964 | struct btrfs_fs_info *fs_info; |
972 | int ret; | 965 | int ret; |
973 | 966 | ||
974 | tree = &BTRFS_I(mapping->host)->io_tree; | ||
975 | if (wbc->sync_mode == WB_SYNC_NONE) { | 967 | if (wbc->sync_mode == WB_SYNC_NONE) { |
976 | 968 | ||
977 | if (wbc->for_kupdate) | 969 | if (wbc->for_kupdate) |
@@ -1010,8 +1002,9 @@ static void btree_invalidatepage(struct page *page, unsigned int offset, | |||
1010 | extent_invalidatepage(tree, page, offset); | 1002 | extent_invalidatepage(tree, page, offset); |
1011 | btree_releasepage(page, GFP_NOFS); | 1003 | btree_releasepage(page, GFP_NOFS); |
1012 | if (PagePrivate(page)) { | 1004 | if (PagePrivate(page)) { |
1013 | printk(KERN_WARNING "btrfs warning page private not zero " | 1005 | btrfs_warn(BTRFS_I(page->mapping->host)->root->fs_info, |
1014 | "on page %llu\n", (unsigned long long)page_offset(page)); | 1006 | "page private not zero on page %llu", |
1007 | (unsigned long long)page_offset(page)); | ||
1015 | ClearPagePrivate(page); | 1008 | ClearPagePrivate(page); |
1016 | set_page_private(page, 0); | 1009 | set_page_private(page, 0); |
1017 | page_cache_release(page); | 1010 | page_cache_release(page); |
@@ -1095,21 +1088,13 @@ int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, u32 blocksize, | |||
1095 | struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, | 1088 | struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, |
1096 | u64 bytenr, u32 blocksize) | 1089 | u64 bytenr, u32 blocksize) |
1097 | { | 1090 | { |
1098 | struct inode *btree_inode = root->fs_info->btree_inode; | 1091 | return find_extent_buffer(root->fs_info, bytenr); |
1099 | struct extent_buffer *eb; | ||
1100 | eb = find_extent_buffer(&BTRFS_I(btree_inode)->io_tree, bytenr); | ||
1101 | return eb; | ||
1102 | } | 1092 | } |
1103 | 1093 | ||
1104 | struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, | 1094 | struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, |
1105 | u64 bytenr, u32 blocksize) | 1095 | u64 bytenr, u32 blocksize) |
1106 | { | 1096 | { |
1107 | struct inode *btree_inode = root->fs_info->btree_inode; | 1097 | return alloc_extent_buffer(root->fs_info, bytenr, blocksize); |
1108 | struct extent_buffer *eb; | ||
1109 | |||
1110 | eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree, | ||
1111 | bytenr, blocksize); | ||
1112 | return eb; | ||
1113 | } | 1098 | } |
1114 | 1099 | ||
1115 | 1100 | ||
@@ -1273,7 +1258,6 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, | |||
1273 | struct btrfs_root *root; | 1258 | struct btrfs_root *root; |
1274 | struct btrfs_key key; | 1259 | struct btrfs_key key; |
1275 | int ret = 0; | 1260 | int ret = 0; |
1276 | u64 bytenr; | ||
1277 | uuid_le uuid; | 1261 | uuid_le uuid; |
1278 | 1262 | ||
1279 | root = btrfs_alloc_root(fs_info); | 1263 | root = btrfs_alloc_root(fs_info); |
@@ -1295,7 +1279,6 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, | |||
1295 | goto fail; | 1279 | goto fail; |
1296 | } | 1280 | } |
1297 | 1281 | ||
1298 | bytenr = leaf->start; | ||
1299 | memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header)); | 1282 | memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header)); |
1300 | btrfs_set_header_bytenr(leaf, leaf->start); | 1283 | btrfs_set_header_bytenr(leaf, leaf->start); |
1301 | btrfs_set_header_generation(leaf, trans->transid); | 1284 | btrfs_set_header_generation(leaf, trans->transid); |
@@ -1616,7 +1599,8 @@ again: | |||
1616 | if (ret) | 1599 | if (ret) |
1617 | goto fail; | 1600 | goto fail; |
1618 | 1601 | ||
1619 | ret = btrfs_find_orphan_item(fs_info->tree_root, location->objectid); | 1602 | ret = btrfs_find_item(fs_info->tree_root, NULL, BTRFS_ORPHAN_OBJECTID, |
1603 | location->objectid, BTRFS_ORPHAN_ITEM_KEY, NULL); | ||
1620 | if (ret < 0) | 1604 | if (ret < 0) |
1621 | goto fail; | 1605 | goto fail; |
1622 | if (ret == 0) | 1606 | if (ret == 0) |
@@ -1684,18 +1668,16 @@ static void end_workqueue_fn(struct btrfs_work *work) | |||
1684 | { | 1668 | { |
1685 | struct bio *bio; | 1669 | struct bio *bio; |
1686 | struct end_io_wq *end_io_wq; | 1670 | struct end_io_wq *end_io_wq; |
1687 | struct btrfs_fs_info *fs_info; | ||
1688 | int error; | 1671 | int error; |
1689 | 1672 | ||
1690 | end_io_wq = container_of(work, struct end_io_wq, work); | 1673 | end_io_wq = container_of(work, struct end_io_wq, work); |
1691 | bio = end_io_wq->bio; | 1674 | bio = end_io_wq->bio; |
1692 | fs_info = end_io_wq->info; | ||
1693 | 1675 | ||
1694 | error = end_io_wq->error; | 1676 | error = end_io_wq->error; |
1695 | bio->bi_private = end_io_wq->private; | 1677 | bio->bi_private = end_io_wq->private; |
1696 | bio->bi_end_io = end_io_wq->end_io; | 1678 | bio->bi_end_io = end_io_wq->end_io; |
1697 | kfree(end_io_wq); | 1679 | kfree(end_io_wq); |
1698 | bio_endio(bio, error); | 1680 | bio_endio_nodec(bio, error); |
1699 | } | 1681 | } |
1700 | 1682 | ||
1701 | static int cleaner_kthread(void *arg) | 1683 | static int cleaner_kthread(void *arg) |
@@ -2080,6 +2062,12 @@ static void del_fs_roots(struct btrfs_fs_info *fs_info) | |||
2080 | for (i = 0; i < ret; i++) | 2062 | for (i = 0; i < ret; i++) |
2081 | btrfs_drop_and_free_fs_root(fs_info, gang[i]); | 2063 | btrfs_drop_and_free_fs_root(fs_info, gang[i]); |
2082 | } | 2064 | } |
2065 | |||
2066 | if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { | ||
2067 | btrfs_free_log_root_tree(NULL, fs_info); | ||
2068 | btrfs_destroy_pinned_extent(fs_info->tree_root, | ||
2069 | fs_info->pinned_extents); | ||
2070 | } | ||
2083 | } | 2071 | } |
2084 | 2072 | ||
2085 | int open_ctree(struct super_block *sb, | 2073 | int open_ctree(struct super_block *sb, |
@@ -2154,6 +2142,7 @@ int open_ctree(struct super_block *sb, | |||
2154 | mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); | 2142 | mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); |
2155 | 2143 | ||
2156 | INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC); | 2144 | INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC); |
2145 | INIT_RADIX_TREE(&fs_info->buffer_radix, GFP_ATOMIC); | ||
2157 | INIT_LIST_HEAD(&fs_info->trans_list); | 2146 | INIT_LIST_HEAD(&fs_info->trans_list); |
2158 | INIT_LIST_HEAD(&fs_info->dead_roots); | 2147 | INIT_LIST_HEAD(&fs_info->dead_roots); |
2159 | INIT_LIST_HEAD(&fs_info->delayed_iputs); | 2148 | INIT_LIST_HEAD(&fs_info->delayed_iputs); |
@@ -2167,6 +2156,7 @@ int open_ctree(struct super_block *sb, | |||
2167 | spin_lock_init(&fs_info->free_chunk_lock); | 2156 | spin_lock_init(&fs_info->free_chunk_lock); |
2168 | spin_lock_init(&fs_info->tree_mod_seq_lock); | 2157 | spin_lock_init(&fs_info->tree_mod_seq_lock); |
2169 | spin_lock_init(&fs_info->super_lock); | 2158 | spin_lock_init(&fs_info->super_lock); |
2159 | spin_lock_init(&fs_info->buffer_lock); | ||
2170 | rwlock_init(&fs_info->tree_mod_log_lock); | 2160 | rwlock_init(&fs_info->tree_mod_log_lock); |
2171 | mutex_init(&fs_info->reloc_mutex); | 2161 | mutex_init(&fs_info->reloc_mutex); |
2172 | seqlock_init(&fs_info->profiles_lock); | 2162 | seqlock_init(&fs_info->profiles_lock); |
@@ -2198,7 +2188,7 @@ int open_ctree(struct super_block *sb, | |||
2198 | fs_info->free_chunk_space = 0; | 2188 | fs_info->free_chunk_space = 0; |
2199 | fs_info->tree_mod_log = RB_ROOT; | 2189 | fs_info->tree_mod_log = RB_ROOT; |
2200 | fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; | 2190 | fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; |
2201 | 2191 | fs_info->avg_delayed_ref_runtime = div64_u64(NSEC_PER_SEC, 64); | |
2202 | /* readahead state */ | 2192 | /* readahead state */ |
2203 | INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT); | 2193 | INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT); |
2204 | spin_lock_init(&fs_info->reada_lock); | 2194 | spin_lock_init(&fs_info->reada_lock); |
@@ -2337,7 +2327,7 @@ int open_ctree(struct super_block *sb, | |||
2337 | * Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k). | 2327 | * Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k). |
2338 | */ | 2328 | */ |
2339 | if (btrfs_check_super_csum(bh->b_data)) { | 2329 | if (btrfs_check_super_csum(bh->b_data)) { |
2340 | printk(KERN_ERR "btrfs: superblock checksum mismatch\n"); | 2330 | printk(KERN_ERR "BTRFS: superblock checksum mismatch\n"); |
2341 | err = -EINVAL; | 2331 | err = -EINVAL; |
2342 | goto fail_alloc; | 2332 | goto fail_alloc; |
2343 | } | 2333 | } |
@@ -2356,7 +2346,7 @@ int open_ctree(struct super_block *sb, | |||
2356 | 2346 | ||
2357 | ret = btrfs_check_super_valid(fs_info, sb->s_flags & MS_RDONLY); | 2347 | ret = btrfs_check_super_valid(fs_info, sb->s_flags & MS_RDONLY); |
2358 | if (ret) { | 2348 | if (ret) { |
2359 | printk(KERN_ERR "btrfs: superblock contains fatal errors\n"); | 2349 | printk(KERN_ERR "BTRFS: superblock contains fatal errors\n"); |
2360 | err = -EINVAL; | 2350 | err = -EINVAL; |
2361 | goto fail_alloc; | 2351 | goto fail_alloc; |
2362 | } | 2352 | } |
@@ -2421,7 +2411,7 @@ int open_ctree(struct super_block *sb, | |||
2421 | features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO; | 2411 | features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO; |
2422 | 2412 | ||
2423 | if (features & BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA) | 2413 | if (features & BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA) |
2424 | printk(KERN_ERR "btrfs: has skinny extents\n"); | 2414 | printk(KERN_ERR "BTRFS: has skinny extents\n"); |
2425 | 2415 | ||
2426 | /* | 2416 | /* |
2427 | * flag our filesystem as having big metadata blocks if | 2417 | * flag our filesystem as having big metadata blocks if |
@@ -2429,7 +2419,7 @@ int open_ctree(struct super_block *sb, | |||
2429 | */ | 2419 | */ |
2430 | if (btrfs_super_leafsize(disk_super) > PAGE_CACHE_SIZE) { | 2420 | if (btrfs_super_leafsize(disk_super) > PAGE_CACHE_SIZE) { |
2431 | if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA)) | 2421 | if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA)) |
2432 | printk(KERN_INFO "btrfs flagging fs with big metadata feature\n"); | 2422 | printk(KERN_INFO "BTRFS: flagging fs with big metadata feature\n"); |
2433 | features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA; | 2423 | features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA; |
2434 | } | 2424 | } |
2435 | 2425 | ||
@@ -2446,7 +2436,7 @@ int open_ctree(struct super_block *sb, | |||
2446 | */ | 2436 | */ |
2447 | if ((features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) && | 2437 | if ((features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) && |
2448 | (sectorsize != leafsize)) { | 2438 | (sectorsize != leafsize)) { |
2449 | printk(KERN_WARNING "btrfs: unequal leaf/node/sector sizes " | 2439 | printk(KERN_WARNING "BTRFS: unequal leaf/node/sector sizes " |
2450 | "are not allowed for mixed block groups on %s\n", | 2440 | "are not allowed for mixed block groups on %s\n", |
2451 | sb->s_id); | 2441 | sb->s_id); |
2452 | goto fail_alloc; | 2442 | goto fail_alloc; |
@@ -2583,12 +2573,12 @@ int open_ctree(struct super_block *sb, | |||
2583 | sb->s_blocksize_bits = blksize_bits(sectorsize); | 2573 | sb->s_blocksize_bits = blksize_bits(sectorsize); |
2584 | 2574 | ||
2585 | if (btrfs_super_magic(disk_super) != BTRFS_MAGIC) { | 2575 | if (btrfs_super_magic(disk_super) != BTRFS_MAGIC) { |
2586 | printk(KERN_INFO "btrfs: valid FS not found on %s\n", sb->s_id); | 2576 | printk(KERN_INFO "BTRFS: valid FS not found on %s\n", sb->s_id); |
2587 | goto fail_sb_buffer; | 2577 | goto fail_sb_buffer; |
2588 | } | 2578 | } |
2589 | 2579 | ||
2590 | if (sectorsize != PAGE_SIZE) { | 2580 | if (sectorsize != PAGE_SIZE) { |
2591 | printk(KERN_WARNING "btrfs: Incompatible sector size(%lu) " | 2581 | printk(KERN_WARNING "BTRFS: Incompatible sector size(%lu) " |
2592 | "found on %s\n", (unsigned long)sectorsize, sb->s_id); | 2582 | "found on %s\n", (unsigned long)sectorsize, sb->s_id); |
2593 | goto fail_sb_buffer; | 2583 | goto fail_sb_buffer; |
2594 | } | 2584 | } |
@@ -2597,7 +2587,7 @@ int open_ctree(struct super_block *sb, | |||
2597 | ret = btrfs_read_sys_array(tree_root); | 2587 | ret = btrfs_read_sys_array(tree_root); |
2598 | mutex_unlock(&fs_info->chunk_mutex); | 2588 | mutex_unlock(&fs_info->chunk_mutex); |
2599 | if (ret) { | 2589 | if (ret) { |
2600 | printk(KERN_WARNING "btrfs: failed to read the system " | 2590 | printk(KERN_WARNING "BTRFS: failed to read the system " |
2601 | "array on %s\n", sb->s_id); | 2591 | "array on %s\n", sb->s_id); |
2602 | goto fail_sb_buffer; | 2592 | goto fail_sb_buffer; |
2603 | } | 2593 | } |
@@ -2614,7 +2604,7 @@ int open_ctree(struct super_block *sb, | |||
2614 | blocksize, generation); | 2604 | blocksize, generation); |
2615 | if (!chunk_root->node || | 2605 | if (!chunk_root->node || |
2616 | !test_bit(EXTENT_BUFFER_UPTODATE, &chunk_root->node->bflags)) { | 2606 | !test_bit(EXTENT_BUFFER_UPTODATE, &chunk_root->node->bflags)) { |
2617 | printk(KERN_WARNING "btrfs: failed to read chunk root on %s\n", | 2607 | printk(KERN_WARNING "BTRFS: failed to read chunk root on %s\n", |
2618 | sb->s_id); | 2608 | sb->s_id); |
2619 | goto fail_tree_roots; | 2609 | goto fail_tree_roots; |
2620 | } | 2610 | } |
@@ -2626,7 +2616,7 @@ int open_ctree(struct super_block *sb, | |||
2626 | 2616 | ||
2627 | ret = btrfs_read_chunk_tree(chunk_root); | 2617 | ret = btrfs_read_chunk_tree(chunk_root); |
2628 | if (ret) { | 2618 | if (ret) { |
2629 | printk(KERN_WARNING "btrfs: failed to read chunk tree on %s\n", | 2619 | printk(KERN_WARNING "BTRFS: failed to read chunk tree on %s\n", |
2630 | sb->s_id); | 2620 | sb->s_id); |
2631 | goto fail_tree_roots; | 2621 | goto fail_tree_roots; |
2632 | } | 2622 | } |
@@ -2638,7 +2628,7 @@ int open_ctree(struct super_block *sb, | |||
2638 | btrfs_close_extra_devices(fs_info, fs_devices, 0); | 2628 | btrfs_close_extra_devices(fs_info, fs_devices, 0); |
2639 | 2629 | ||
2640 | if (!fs_devices->latest_bdev) { | 2630 | if (!fs_devices->latest_bdev) { |
2641 | printk(KERN_CRIT "btrfs: failed to read devices on %s\n", | 2631 | printk(KERN_CRIT "BTRFS: failed to read devices on %s\n", |
2642 | sb->s_id); | 2632 | sb->s_id); |
2643 | goto fail_tree_roots; | 2633 | goto fail_tree_roots; |
2644 | } | 2634 | } |
@@ -2653,7 +2643,7 @@ retry_root_backup: | |||
2653 | blocksize, generation); | 2643 | blocksize, generation); |
2654 | if (!tree_root->node || | 2644 | if (!tree_root->node || |
2655 | !test_bit(EXTENT_BUFFER_UPTODATE, &tree_root->node->bflags)) { | 2645 | !test_bit(EXTENT_BUFFER_UPTODATE, &tree_root->node->bflags)) { |
2656 | printk(KERN_WARNING "btrfs: failed to read tree root on %s\n", | 2646 | printk(KERN_WARNING "BTRFS: failed to read tree root on %s\n", |
2657 | sb->s_id); | 2647 | sb->s_id); |
2658 | 2648 | ||
2659 | goto recovery_tree_root; | 2649 | goto recovery_tree_root; |
@@ -2724,50 +2714,56 @@ retry_root_backup: | |||
2724 | 2714 | ||
2725 | ret = btrfs_recover_balance(fs_info); | 2715 | ret = btrfs_recover_balance(fs_info); |
2726 | if (ret) { | 2716 | if (ret) { |
2727 | printk(KERN_WARNING "btrfs: failed to recover balance\n"); | 2717 | printk(KERN_WARNING "BTRFS: failed to recover balance\n"); |
2728 | goto fail_block_groups; | 2718 | goto fail_block_groups; |
2729 | } | 2719 | } |
2730 | 2720 | ||
2731 | ret = btrfs_init_dev_stats(fs_info); | 2721 | ret = btrfs_init_dev_stats(fs_info); |
2732 | if (ret) { | 2722 | if (ret) { |
2733 | printk(KERN_ERR "btrfs: failed to init dev_stats: %d\n", | 2723 | printk(KERN_ERR "BTRFS: failed to init dev_stats: %d\n", |
2734 | ret); | 2724 | ret); |
2735 | goto fail_block_groups; | 2725 | goto fail_block_groups; |
2736 | } | 2726 | } |
2737 | 2727 | ||
2738 | ret = btrfs_init_dev_replace(fs_info); | 2728 | ret = btrfs_init_dev_replace(fs_info); |
2739 | if (ret) { | 2729 | if (ret) { |
2740 | pr_err("btrfs: failed to init dev_replace: %d\n", ret); | 2730 | pr_err("BTRFS: failed to init dev_replace: %d\n", ret); |
2741 | goto fail_block_groups; | 2731 | goto fail_block_groups; |
2742 | } | 2732 | } |
2743 | 2733 | ||
2744 | btrfs_close_extra_devices(fs_info, fs_devices, 1); | 2734 | btrfs_close_extra_devices(fs_info, fs_devices, 1); |
2745 | 2735 | ||
2746 | ret = btrfs_init_space_info(fs_info); | 2736 | ret = btrfs_sysfs_add_one(fs_info); |
2747 | if (ret) { | 2737 | if (ret) { |
2748 | printk(KERN_ERR "Failed to initial space info: %d\n", ret); | 2738 | pr_err("BTRFS: failed to init sysfs interface: %d\n", ret); |
2749 | goto fail_block_groups; | 2739 | goto fail_block_groups; |
2750 | } | 2740 | } |
2751 | 2741 | ||
2742 | ret = btrfs_init_space_info(fs_info); | ||
2743 | if (ret) { | ||
2744 | printk(KERN_ERR "BTRFS: Failed to initial space info: %d\n", ret); | ||
2745 | goto fail_sysfs; | ||
2746 | } | ||
2747 | |||
2752 | ret = btrfs_read_block_groups(extent_root); | 2748 | ret = btrfs_read_block_groups(extent_root); |
2753 | if (ret) { | 2749 | if (ret) { |
2754 | printk(KERN_ERR "Failed to read block groups: %d\n", ret); | 2750 | printk(KERN_ERR "BTRFS: Failed to read block groups: %d\n", ret); |
2755 | goto fail_block_groups; | 2751 | goto fail_sysfs; |
2756 | } | 2752 | } |
2757 | fs_info->num_tolerated_disk_barrier_failures = | 2753 | fs_info->num_tolerated_disk_barrier_failures = |
2758 | btrfs_calc_num_tolerated_disk_barrier_failures(fs_info); | 2754 | btrfs_calc_num_tolerated_disk_barrier_failures(fs_info); |
2759 | if (fs_info->fs_devices->missing_devices > | 2755 | if (fs_info->fs_devices->missing_devices > |
2760 | fs_info->num_tolerated_disk_barrier_failures && | 2756 | fs_info->num_tolerated_disk_barrier_failures && |
2761 | !(sb->s_flags & MS_RDONLY)) { | 2757 | !(sb->s_flags & MS_RDONLY)) { |
2762 | printk(KERN_WARNING | 2758 | printk(KERN_WARNING "BTRFS: " |
2763 | "Btrfs: too many missing devices, writeable mount is not allowed\n"); | 2759 | "too many missing devices, writeable mount is not allowed\n"); |
2764 | goto fail_block_groups; | 2760 | goto fail_sysfs; |
2765 | } | 2761 | } |
2766 | 2762 | ||
2767 | fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, | 2763 | fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, |
2768 | "btrfs-cleaner"); | 2764 | "btrfs-cleaner"); |
2769 | if (IS_ERR(fs_info->cleaner_kthread)) | 2765 | if (IS_ERR(fs_info->cleaner_kthread)) |
2770 | goto fail_block_groups; | 2766 | goto fail_sysfs; |
2771 | 2767 | ||
2772 | fs_info->transaction_kthread = kthread_run(transaction_kthread, | 2768 | fs_info->transaction_kthread = kthread_run(transaction_kthread, |
2773 | tree_root, | 2769 | tree_root, |
@@ -2778,11 +2774,15 @@ retry_root_backup: | |||
2778 | if (!btrfs_test_opt(tree_root, SSD) && | 2774 | if (!btrfs_test_opt(tree_root, SSD) && |
2779 | !btrfs_test_opt(tree_root, NOSSD) && | 2775 | !btrfs_test_opt(tree_root, NOSSD) && |
2780 | !fs_info->fs_devices->rotating) { | 2776 | !fs_info->fs_devices->rotating) { |
2781 | printk(KERN_INFO "Btrfs detected SSD devices, enabling SSD " | 2777 | printk(KERN_INFO "BTRFS: detected SSD devices, enabling SSD " |
2782 | "mode\n"); | 2778 | "mode\n"); |
2783 | btrfs_set_opt(fs_info->mount_opt, SSD); | 2779 | btrfs_set_opt(fs_info->mount_opt, SSD); |
2784 | } | 2780 | } |
2785 | 2781 | ||
2782 | /* Set the real inode map cache flag */ | ||
2783 | if (btrfs_test_opt(tree_root, CHANGE_INODE_CACHE)) | ||
2784 | btrfs_set_opt(tree_root->fs_info->mount_opt, INODE_MAP_CACHE); | ||
2785 | |||
2786 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY | 2786 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY |
2787 | if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) { | 2787 | if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) { |
2788 | ret = btrfsic_mount(tree_root, fs_devices, | 2788 | ret = btrfsic_mount(tree_root, fs_devices, |
@@ -2791,7 +2791,7 @@ retry_root_backup: | |||
2791 | 1 : 0, | 2791 | 1 : 0, |
2792 | fs_info->check_integrity_print_mask); | 2792 | fs_info->check_integrity_print_mask); |
2793 | if (ret) | 2793 | if (ret) |
2794 | printk(KERN_WARNING "btrfs: failed to initialize" | 2794 | printk(KERN_WARNING "BTRFS: failed to initialize" |
2795 | " integrity check module %s\n", sb->s_id); | 2795 | " integrity check module %s\n", sb->s_id); |
2796 | } | 2796 | } |
2797 | #endif | 2797 | #endif |
@@ -2804,7 +2804,7 @@ retry_root_backup: | |||
2804 | u64 bytenr = btrfs_super_log_root(disk_super); | 2804 | u64 bytenr = btrfs_super_log_root(disk_super); |
2805 | 2805 | ||
2806 | if (fs_devices->rw_devices == 0) { | 2806 | if (fs_devices->rw_devices == 0) { |
2807 | printk(KERN_WARNING "Btrfs log replay required " | 2807 | printk(KERN_WARNING "BTRFS: log replay required " |
2808 | "on RO media\n"); | 2808 | "on RO media\n"); |
2809 | err = -EIO; | 2809 | err = -EIO; |
2810 | goto fail_qgroup; | 2810 | goto fail_qgroup; |
@@ -2827,7 +2827,7 @@ retry_root_backup: | |||
2827 | generation + 1); | 2827 | generation + 1); |
2828 | if (!log_tree_root->node || | 2828 | if (!log_tree_root->node || |
2829 | !extent_buffer_uptodate(log_tree_root->node)) { | 2829 | !extent_buffer_uptodate(log_tree_root->node)) { |
2830 | printk(KERN_ERR "btrfs: failed to read log tree\n"); | 2830 | printk(KERN_ERR "BTRFS: failed to read log tree\n"); |
2831 | free_extent_buffer(log_tree_root->node); | 2831 | free_extent_buffer(log_tree_root->node); |
2832 | kfree(log_tree_root); | 2832 | kfree(log_tree_root); |
2833 | goto fail_trans_kthread; | 2833 | goto fail_trans_kthread; |
@@ -2861,7 +2861,7 @@ retry_root_backup: | |||
2861 | ret = btrfs_recover_relocation(tree_root); | 2861 | ret = btrfs_recover_relocation(tree_root); |
2862 | if (ret < 0) { | 2862 | if (ret < 0) { |
2863 | printk(KERN_WARNING | 2863 | printk(KERN_WARNING |
2864 | "btrfs: failed to recover relocation\n"); | 2864 | "BTRFS: failed to recover relocation\n"); |
2865 | err = -EINVAL; | 2865 | err = -EINVAL; |
2866 | goto fail_qgroup; | 2866 | goto fail_qgroup; |
2867 | } | 2867 | } |
@@ -2891,14 +2891,14 @@ retry_root_backup: | |||
2891 | 2891 | ||
2892 | ret = btrfs_resume_balance_async(fs_info); | 2892 | ret = btrfs_resume_balance_async(fs_info); |
2893 | if (ret) { | 2893 | if (ret) { |
2894 | printk(KERN_WARNING "btrfs: failed to resume balance\n"); | 2894 | printk(KERN_WARNING "BTRFS: failed to resume balance\n"); |
2895 | close_ctree(tree_root); | 2895 | close_ctree(tree_root); |
2896 | return ret; | 2896 | return ret; |
2897 | } | 2897 | } |
2898 | 2898 | ||
2899 | ret = btrfs_resume_dev_replace_async(fs_info); | 2899 | ret = btrfs_resume_dev_replace_async(fs_info); |
2900 | if (ret) { | 2900 | if (ret) { |
2901 | pr_warn("btrfs: failed to resume dev_replace\n"); | 2901 | pr_warn("BTRFS: failed to resume dev_replace\n"); |
2902 | close_ctree(tree_root); | 2902 | close_ctree(tree_root); |
2903 | return ret; | 2903 | return ret; |
2904 | } | 2904 | } |
@@ -2906,20 +2906,20 @@ retry_root_backup: | |||
2906 | btrfs_qgroup_rescan_resume(fs_info); | 2906 | btrfs_qgroup_rescan_resume(fs_info); |
2907 | 2907 | ||
2908 | if (create_uuid_tree) { | 2908 | if (create_uuid_tree) { |
2909 | pr_info("btrfs: creating UUID tree\n"); | 2909 | pr_info("BTRFS: creating UUID tree\n"); |
2910 | ret = btrfs_create_uuid_tree(fs_info); | 2910 | ret = btrfs_create_uuid_tree(fs_info); |
2911 | if (ret) { | 2911 | if (ret) { |
2912 | pr_warn("btrfs: failed to create the UUID tree %d\n", | 2912 | pr_warn("BTRFS: failed to create the UUID tree %d\n", |
2913 | ret); | 2913 | ret); |
2914 | close_ctree(tree_root); | 2914 | close_ctree(tree_root); |
2915 | return ret; | 2915 | return ret; |
2916 | } | 2916 | } |
2917 | } else if (check_uuid_tree || | 2917 | } else if (check_uuid_tree || |
2918 | btrfs_test_opt(tree_root, RESCAN_UUID_TREE)) { | 2918 | btrfs_test_opt(tree_root, RESCAN_UUID_TREE)) { |
2919 | pr_info("btrfs: checking UUID tree\n"); | 2919 | pr_info("BTRFS: checking UUID tree\n"); |
2920 | ret = btrfs_check_uuid_tree(fs_info); | 2920 | ret = btrfs_check_uuid_tree(fs_info); |
2921 | if (ret) { | 2921 | if (ret) { |
2922 | pr_warn("btrfs: failed to check the UUID tree %d\n", | 2922 | pr_warn("BTRFS: failed to check the UUID tree %d\n", |
2923 | ret); | 2923 | ret); |
2924 | close_ctree(tree_root); | 2924 | close_ctree(tree_root); |
2925 | return ret; | 2925 | return ret; |
@@ -2945,6 +2945,9 @@ fail_cleaner: | |||
2945 | */ | 2945 | */ |
2946 | filemap_write_and_wait(fs_info->btree_inode->i_mapping); | 2946 | filemap_write_and_wait(fs_info->btree_inode->i_mapping); |
2947 | 2947 | ||
2948 | fail_sysfs: | ||
2949 | btrfs_sysfs_remove_one(fs_info); | ||
2950 | |||
2948 | fail_block_groups: | 2951 | fail_block_groups: |
2949 | btrfs_put_block_group_cache(fs_info); | 2952 | btrfs_put_block_group_cache(fs_info); |
2950 | btrfs_free_block_groups(fs_info); | 2953 | btrfs_free_block_groups(fs_info); |
@@ -3000,7 +3003,7 @@ static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate) | |||
3000 | struct btrfs_device *device = (struct btrfs_device *) | 3003 | struct btrfs_device *device = (struct btrfs_device *) |
3001 | bh->b_private; | 3004 | bh->b_private; |
3002 | 3005 | ||
3003 | printk_ratelimited_in_rcu(KERN_WARNING "lost page write due to " | 3006 | printk_ratelimited_in_rcu(KERN_WARNING "BTRFS: lost page write due to " |
3004 | "I/O error on %s\n", | 3007 | "I/O error on %s\n", |
3005 | rcu_str_deref(device->name)); | 3008 | rcu_str_deref(device->name)); |
3006 | /* note, we dont' set_buffer_write_io_error because we have | 3009 | /* note, we dont' set_buffer_write_io_error because we have |
@@ -3119,7 +3122,7 @@ static int write_dev_supers(struct btrfs_device *device, | |||
3119 | bh = __getblk(device->bdev, bytenr / 4096, | 3122 | bh = __getblk(device->bdev, bytenr / 4096, |
3120 | BTRFS_SUPER_INFO_SIZE); | 3123 | BTRFS_SUPER_INFO_SIZE); |
3121 | if (!bh) { | 3124 | if (!bh) { |
3122 | printk(KERN_ERR "btrfs: couldn't get super " | 3125 | printk(KERN_ERR "BTRFS: couldn't get super " |
3123 | "buffer head for bytenr %Lu\n", bytenr); | 3126 | "buffer head for bytenr %Lu\n", bytenr); |
3124 | errors++; | 3127 | errors++; |
3125 | continue; | 3128 | continue; |
@@ -3140,7 +3143,10 @@ static int write_dev_supers(struct btrfs_device *device, | |||
3140 | * we fua the first super. The others we allow | 3143 | * we fua the first super. The others we allow |
3141 | * to go down lazy. | 3144 | * to go down lazy. |
3142 | */ | 3145 | */ |
3143 | ret = btrfsic_submit_bh(WRITE_FUA, bh); | 3146 | if (i == 0) |
3147 | ret = btrfsic_submit_bh(WRITE_FUA, bh); | ||
3148 | else | ||
3149 | ret = btrfsic_submit_bh(WRITE_SYNC, bh); | ||
3144 | if (ret) | 3150 | if (ret) |
3145 | errors++; | 3151 | errors++; |
3146 | } | 3152 | } |
@@ -3186,7 +3192,7 @@ static int write_dev_flush(struct btrfs_device *device, int wait) | |||
3186 | wait_for_completion(&device->flush_wait); | 3192 | wait_for_completion(&device->flush_wait); |
3187 | 3193 | ||
3188 | if (bio_flagged(bio, BIO_EOPNOTSUPP)) { | 3194 | if (bio_flagged(bio, BIO_EOPNOTSUPP)) { |
3189 | printk_in_rcu("btrfs: disabling barriers on dev %s\n", | 3195 | printk_in_rcu("BTRFS: disabling barriers on dev %s\n", |
3190 | rcu_str_deref(device->name)); | 3196 | rcu_str_deref(device->name)); |
3191 | device->nobarriers = 1; | 3197 | device->nobarriers = 1; |
3192 | } else if (!bio_flagged(bio, BIO_UPTODATE)) { | 3198 | } else if (!bio_flagged(bio, BIO_UPTODATE)) { |
@@ -3407,7 +3413,7 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors) | |||
3407 | total_errors++; | 3413 | total_errors++; |
3408 | } | 3414 | } |
3409 | if (total_errors > max_errors) { | 3415 | if (total_errors > max_errors) { |
3410 | printk(KERN_ERR "btrfs: %d errors while writing supers\n", | 3416 | btrfs_err(root->fs_info, "%d errors while writing supers", |
3411 | total_errors); | 3417 | total_errors); |
3412 | mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); | 3418 | mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); |
3413 | 3419 | ||
@@ -3455,10 +3461,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, | |||
3455 | if (btrfs_root_refs(&root->root_item) == 0) | 3461 | if (btrfs_root_refs(&root->root_item) == 0) |
3456 | synchronize_srcu(&fs_info->subvol_srcu); | 3462 | synchronize_srcu(&fs_info->subvol_srcu); |
3457 | 3463 | ||
3458 | if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { | 3464 | if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) |
3459 | btrfs_free_log(NULL, root); | 3465 | btrfs_free_log(NULL, root); |
3460 | btrfs_free_log_root_tree(NULL, fs_info); | ||
3461 | } | ||
3462 | 3466 | ||
3463 | __btrfs_remove_free_space_cache(root->free_ino_pinned); | 3467 | __btrfs_remove_free_space_cache(root->free_ino_pinned); |
3464 | __btrfs_remove_free_space_cache(root->free_ino_ctl); | 3468 | __btrfs_remove_free_space_cache(root->free_ino_ctl); |
@@ -3563,14 +3567,12 @@ int close_ctree(struct btrfs_root *root) | |||
3563 | if (!(fs_info->sb->s_flags & MS_RDONLY)) { | 3567 | if (!(fs_info->sb->s_flags & MS_RDONLY)) { |
3564 | ret = btrfs_commit_super(root); | 3568 | ret = btrfs_commit_super(root); |
3565 | if (ret) | 3569 | if (ret) |
3566 | printk(KERN_ERR "btrfs: commit super ret %d\n", ret); | 3570 | btrfs_err(root->fs_info, "commit super ret %d", ret); |
3567 | } | 3571 | } |
3568 | 3572 | ||
3569 | if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) | 3573 | if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) |
3570 | btrfs_error_commit_super(root); | 3574 | btrfs_error_commit_super(root); |
3571 | 3575 | ||
3572 | btrfs_put_block_group_cache(fs_info); | ||
3573 | |||
3574 | kthread_stop(fs_info->transaction_kthread); | 3576 | kthread_stop(fs_info->transaction_kthread); |
3575 | kthread_stop(fs_info->cleaner_kthread); | 3577 | kthread_stop(fs_info->cleaner_kthread); |
3576 | 3578 | ||
@@ -3580,12 +3582,16 @@ int close_ctree(struct btrfs_root *root) | |||
3580 | btrfs_free_qgroup_config(root->fs_info); | 3582 | btrfs_free_qgroup_config(root->fs_info); |
3581 | 3583 | ||
3582 | if (percpu_counter_sum(&fs_info->delalloc_bytes)) { | 3584 | if (percpu_counter_sum(&fs_info->delalloc_bytes)) { |
3583 | printk(KERN_INFO "btrfs: at unmount delalloc count %lld\n", | 3585 | btrfs_info(root->fs_info, "at unmount delalloc count %lld", |
3584 | percpu_counter_sum(&fs_info->delalloc_bytes)); | 3586 | percpu_counter_sum(&fs_info->delalloc_bytes)); |
3585 | } | 3587 | } |
3586 | 3588 | ||
3589 | btrfs_sysfs_remove_one(fs_info); | ||
3590 | |||
3587 | del_fs_roots(fs_info); | 3591 | del_fs_roots(fs_info); |
3588 | 3592 | ||
3593 | btrfs_put_block_group_cache(fs_info); | ||
3594 | |||
3589 | btrfs_free_block_groups(fs_info); | 3595 | btrfs_free_block_groups(fs_info); |
3590 | 3596 | ||
3591 | btrfs_stop_all_workers(fs_info); | 3597 | btrfs_stop_all_workers(fs_info); |
@@ -3803,55 +3809,54 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, | |||
3803 | delayed_refs = &trans->delayed_refs; | 3809 | delayed_refs = &trans->delayed_refs; |
3804 | 3810 | ||
3805 | spin_lock(&delayed_refs->lock); | 3811 | spin_lock(&delayed_refs->lock); |
3806 | if (delayed_refs->num_entries == 0) { | 3812 | if (atomic_read(&delayed_refs->num_entries) == 0) { |
3807 | spin_unlock(&delayed_refs->lock); | 3813 | spin_unlock(&delayed_refs->lock); |
3808 | printk(KERN_INFO "delayed_refs has NO entry\n"); | 3814 | btrfs_info(root->fs_info, "delayed_refs has NO entry"); |
3809 | return ret; | 3815 | return ret; |
3810 | } | 3816 | } |
3811 | 3817 | ||
3812 | while ((node = rb_first(&delayed_refs->root)) != NULL) { | 3818 | while ((node = rb_first(&delayed_refs->href_root)) != NULL) { |
3813 | struct btrfs_delayed_ref_head *head = NULL; | 3819 | struct btrfs_delayed_ref_head *head; |
3814 | bool pin_bytes = false; | 3820 | bool pin_bytes = false; |
3815 | 3821 | ||
3816 | ref = rb_entry(node, struct btrfs_delayed_ref_node, rb_node); | 3822 | head = rb_entry(node, struct btrfs_delayed_ref_head, |
3817 | atomic_set(&ref->refs, 1); | 3823 | href_node); |
3818 | if (btrfs_delayed_ref_is_head(ref)) { | 3824 | if (!mutex_trylock(&head->mutex)) { |
3819 | 3825 | atomic_inc(&head->node.refs); | |
3820 | head = btrfs_delayed_node_to_head(ref); | 3826 | spin_unlock(&delayed_refs->lock); |
3821 | if (!mutex_trylock(&head->mutex)) { | ||
3822 | atomic_inc(&ref->refs); | ||
3823 | spin_unlock(&delayed_refs->lock); | ||
3824 | |||
3825 | /* Need to wait for the delayed ref to run */ | ||
3826 | mutex_lock(&head->mutex); | ||
3827 | mutex_unlock(&head->mutex); | ||
3828 | btrfs_put_delayed_ref(ref); | ||
3829 | |||
3830 | spin_lock(&delayed_refs->lock); | ||
3831 | continue; | ||
3832 | } | ||
3833 | 3827 | ||
3834 | if (head->must_insert_reserved) | 3828 | mutex_lock(&head->mutex); |
3835 | pin_bytes = true; | ||
3836 | btrfs_free_delayed_extent_op(head->extent_op); | ||
3837 | delayed_refs->num_heads--; | ||
3838 | if (list_empty(&head->cluster)) | ||
3839 | delayed_refs->num_heads_ready--; | ||
3840 | list_del_init(&head->cluster); | ||
3841 | } | ||
3842 | |||
3843 | ref->in_tree = 0; | ||
3844 | rb_erase(&ref->rb_node, &delayed_refs->root); | ||
3845 | delayed_refs->num_entries--; | ||
3846 | spin_unlock(&delayed_refs->lock); | ||
3847 | if (head) { | ||
3848 | if (pin_bytes) | ||
3849 | btrfs_pin_extent(root, ref->bytenr, | ||
3850 | ref->num_bytes, 1); | ||
3851 | mutex_unlock(&head->mutex); | 3829 | mutex_unlock(&head->mutex); |
3830 | btrfs_put_delayed_ref(&head->node); | ||
3831 | spin_lock(&delayed_refs->lock); | ||
3832 | continue; | ||
3833 | } | ||
3834 | spin_lock(&head->lock); | ||
3835 | while ((node = rb_first(&head->ref_root)) != NULL) { | ||
3836 | ref = rb_entry(node, struct btrfs_delayed_ref_node, | ||
3837 | rb_node); | ||
3838 | ref->in_tree = 0; | ||
3839 | rb_erase(&ref->rb_node, &head->ref_root); | ||
3840 | atomic_dec(&delayed_refs->num_entries); | ||
3841 | btrfs_put_delayed_ref(ref); | ||
3852 | } | 3842 | } |
3853 | btrfs_put_delayed_ref(ref); | 3843 | if (head->must_insert_reserved) |
3844 | pin_bytes = true; | ||
3845 | btrfs_free_delayed_extent_op(head->extent_op); | ||
3846 | delayed_refs->num_heads--; | ||
3847 | if (head->processing == 0) | ||
3848 | delayed_refs->num_heads_ready--; | ||
3849 | atomic_dec(&delayed_refs->num_entries); | ||
3850 | head->node.in_tree = 0; | ||
3851 | rb_erase(&head->href_node, &delayed_refs->href_root); | ||
3852 | spin_unlock(&head->lock); | ||
3853 | spin_unlock(&delayed_refs->lock); | ||
3854 | mutex_unlock(&head->mutex); | ||
3854 | 3855 | ||
3856 | if (pin_bytes) | ||
3857 | btrfs_pin_extent(root, head->node.bytenr, | ||
3858 | head->node.num_bytes, 1); | ||
3859 | btrfs_put_delayed_ref(&head->node); | ||
3855 | cond_resched(); | 3860 | cond_resched(); |
3856 | spin_lock(&delayed_refs->lock); | 3861 | spin_lock(&delayed_refs->lock); |
3857 | } | 3862 | } |