diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-30 23:08:20 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-30 23:08:20 -0500 |
commit | e7651b819e90da924991d727d3c007200a18670d (patch) | |
tree | e7a943b5bb56c384972944fd86767a3f079b8a98 /fs/btrfs/disk-io.c | |
parent | 060e8e3b6f8fc0ba97de2276249fbd80fa25b0a2 (diff) | |
parent | cf93da7bcf450cb4595055d491a0519cb39e68ed (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs updates from Chris Mason:
"This is a pretty big pull, and most of these changes have been
floating in btrfs-next for a long time. Filipe's properties work is a
cool building block for inheriting attributes like compression down on
a per inode basis.
Jeff Mahoney kicked in code to export filesystem info into sysfs.
Otherwise, lots of performance improvements, cleanups and bug fixes.
Looks like there are still a few other small pending incrementals, but
I wanted to get the bulk of this in first"
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (149 commits)
Btrfs: fix spin_unlock in check_ref_cleanup
Btrfs: setup inode location during btrfs_init_inode_locked
Btrfs: don't use ram_bytes for uncompressed inline items
Btrfs: fix btrfs_search_slot_for_read backwards iteration
Btrfs: do not export ulist functions
Btrfs: rework ulist with list+rb_tree
Btrfs: fix memory leaks on walking backrefs failure
Btrfs: fix send file hole detection leading to data corruption
Btrfs: add a reschedule point in btrfs_find_all_roots()
Btrfs: make send's file extent item search more efficient
Btrfs: fix to catch all errors when resolving indirect ref
Btrfs: fix protection between walking backrefs and root deletion
btrfs: fix warning while merging two adjacent extents
Btrfs: fix infinite path build loops in incremental send
btrfs: undo sysfs when open_ctree() fails
Btrfs: fix snprintf usage by send's gen_unique_name
btrfs: fix defrag 32-bit integer overflow
btrfs: sysfs: list the NO_HOLES feature
btrfs: sysfs: don't show reserved incompat feature
btrfs: call permission checks earlier in ioctls and return EPERM
...
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 253 |
1 files changed, 131 insertions, 122 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index e71039ea66cf..0e69295d0031 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -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> |
@@ -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; |
@@ -964,11 +961,9 @@ static int btree_migratepage(struct address_space *mapping, | |||
964 | static int btree_writepages(struct address_space *mapping, | 961 | static int btree_writepages(struct address_space *mapping, |
965 | struct writeback_control *wbc) | 962 | struct writeback_control *wbc) |
966 | { | 963 | { |
967 | struct extent_io_tree *tree; | ||
968 | struct btrfs_fs_info *fs_info; | 964 | struct btrfs_fs_info *fs_info; |
969 | int ret; | 965 | int ret; |
970 | 966 | ||
971 | tree = &BTRFS_I(mapping->host)->io_tree; | ||
972 | if (wbc->sync_mode == WB_SYNC_NONE) { | 967 | if (wbc->sync_mode == WB_SYNC_NONE) { |
973 | 968 | ||
974 | if (wbc->for_kupdate) | 969 | if (wbc->for_kupdate) |
@@ -1007,8 +1002,9 @@ static void btree_invalidatepage(struct page *page, unsigned int offset, | |||
1007 | extent_invalidatepage(tree, page, offset); | 1002 | extent_invalidatepage(tree, page, offset); |
1008 | btree_releasepage(page, GFP_NOFS); | 1003 | btree_releasepage(page, GFP_NOFS); |
1009 | if (PagePrivate(page)) { | 1004 | if (PagePrivate(page)) { |
1010 | printk(KERN_WARNING "btrfs warning page private not zero " | 1005 | btrfs_warn(BTRFS_I(page->mapping->host)->root->fs_info, |
1011 | "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)); | ||
1012 | ClearPagePrivate(page); | 1008 | ClearPagePrivate(page); |
1013 | set_page_private(page, 0); | 1009 | set_page_private(page, 0); |
1014 | page_cache_release(page); | 1010 | page_cache_release(page); |
@@ -1092,21 +1088,13 @@ int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, u32 blocksize, | |||
1092 | struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, | 1088 | struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, |
1093 | u64 bytenr, u32 blocksize) | 1089 | u64 bytenr, u32 blocksize) |
1094 | { | 1090 | { |
1095 | struct inode *btree_inode = root->fs_info->btree_inode; | 1091 | return find_extent_buffer(root->fs_info, bytenr); |
1096 | struct extent_buffer *eb; | ||
1097 | eb = find_extent_buffer(&BTRFS_I(btree_inode)->io_tree, bytenr); | ||
1098 | return eb; | ||
1099 | } | 1092 | } |
1100 | 1093 | ||
1101 | 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, |
1102 | u64 bytenr, u32 blocksize) | 1095 | u64 bytenr, u32 blocksize) |
1103 | { | 1096 | { |
1104 | struct inode *btree_inode = root->fs_info->btree_inode; | 1097 | return alloc_extent_buffer(root->fs_info, bytenr, blocksize); |
1105 | struct extent_buffer *eb; | ||
1106 | |||
1107 | eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree, | ||
1108 | bytenr, blocksize); | ||
1109 | return eb; | ||
1110 | } | 1098 | } |
1111 | 1099 | ||
1112 | 1100 | ||
@@ -1270,7 +1258,6 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, | |||
1270 | struct btrfs_root *root; | 1258 | struct btrfs_root *root; |
1271 | struct btrfs_key key; | 1259 | struct btrfs_key key; |
1272 | int ret = 0; | 1260 | int ret = 0; |
1273 | u64 bytenr; | ||
1274 | uuid_le uuid; | 1261 | uuid_le uuid; |
1275 | 1262 | ||
1276 | root = btrfs_alloc_root(fs_info); | 1263 | root = btrfs_alloc_root(fs_info); |
@@ -1292,7 +1279,6 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, | |||
1292 | goto fail; | 1279 | goto fail; |
1293 | } | 1280 | } |
1294 | 1281 | ||
1295 | bytenr = leaf->start; | ||
1296 | memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header)); | 1282 | memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header)); |
1297 | btrfs_set_header_bytenr(leaf, leaf->start); | 1283 | btrfs_set_header_bytenr(leaf, leaf->start); |
1298 | btrfs_set_header_generation(leaf, trans->transid); | 1284 | btrfs_set_header_generation(leaf, trans->transid); |
@@ -1613,7 +1599,8 @@ again: | |||
1613 | if (ret) | 1599 | if (ret) |
1614 | goto fail; | 1600 | goto fail; |
1615 | 1601 | ||
1616 | 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); | ||
1617 | if (ret < 0) | 1604 | if (ret < 0) |
1618 | goto fail; | 1605 | goto fail; |
1619 | if (ret == 0) | 1606 | if (ret == 0) |
@@ -1681,12 +1668,10 @@ static void end_workqueue_fn(struct btrfs_work *work) | |||
1681 | { | 1668 | { |
1682 | struct bio *bio; | 1669 | struct bio *bio; |
1683 | struct end_io_wq *end_io_wq; | 1670 | struct end_io_wq *end_io_wq; |
1684 | struct btrfs_fs_info *fs_info; | ||
1685 | int error; | 1671 | int error; |
1686 | 1672 | ||
1687 | end_io_wq = container_of(work, struct end_io_wq, work); | 1673 | end_io_wq = container_of(work, struct end_io_wq, work); |
1688 | bio = end_io_wq->bio; | 1674 | bio = end_io_wq->bio; |
1689 | fs_info = end_io_wq->info; | ||
1690 | 1675 | ||
1691 | error = end_io_wq->error; | 1676 | error = end_io_wq->error; |
1692 | bio->bi_private = end_io_wq->private; | 1677 | bio->bi_private = end_io_wq->private; |
@@ -2077,6 +2062,12 @@ static void del_fs_roots(struct btrfs_fs_info *fs_info) | |||
2077 | for (i = 0; i < ret; i++) | 2062 | for (i = 0; i < ret; i++) |
2078 | btrfs_drop_and_free_fs_root(fs_info, gang[i]); | 2063 | btrfs_drop_and_free_fs_root(fs_info, gang[i]); |
2079 | } | 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 | } | ||
2080 | } | 2071 | } |
2081 | 2072 | ||
2082 | int open_ctree(struct super_block *sb, | 2073 | int open_ctree(struct super_block *sb, |
@@ -2151,6 +2142,7 @@ int open_ctree(struct super_block *sb, | |||
2151 | 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); |
2152 | 2143 | ||
2153 | 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); | ||
2154 | INIT_LIST_HEAD(&fs_info->trans_list); | 2146 | INIT_LIST_HEAD(&fs_info->trans_list); |
2155 | INIT_LIST_HEAD(&fs_info->dead_roots); | 2147 | INIT_LIST_HEAD(&fs_info->dead_roots); |
2156 | INIT_LIST_HEAD(&fs_info->delayed_iputs); | 2148 | INIT_LIST_HEAD(&fs_info->delayed_iputs); |
@@ -2164,6 +2156,7 @@ int open_ctree(struct super_block *sb, | |||
2164 | spin_lock_init(&fs_info->free_chunk_lock); | 2156 | spin_lock_init(&fs_info->free_chunk_lock); |
2165 | spin_lock_init(&fs_info->tree_mod_seq_lock); | 2157 | spin_lock_init(&fs_info->tree_mod_seq_lock); |
2166 | spin_lock_init(&fs_info->super_lock); | 2158 | spin_lock_init(&fs_info->super_lock); |
2159 | spin_lock_init(&fs_info->buffer_lock); | ||
2167 | rwlock_init(&fs_info->tree_mod_log_lock); | 2160 | rwlock_init(&fs_info->tree_mod_log_lock); |
2168 | mutex_init(&fs_info->reloc_mutex); | 2161 | mutex_init(&fs_info->reloc_mutex); |
2169 | seqlock_init(&fs_info->profiles_lock); | 2162 | seqlock_init(&fs_info->profiles_lock); |
@@ -2195,7 +2188,7 @@ int open_ctree(struct super_block *sb, | |||
2195 | fs_info->free_chunk_space = 0; | 2188 | fs_info->free_chunk_space = 0; |
2196 | fs_info->tree_mod_log = RB_ROOT; | 2189 | fs_info->tree_mod_log = RB_ROOT; |
2197 | fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; | 2190 | fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; |
2198 | 2191 | fs_info->avg_delayed_ref_runtime = div64_u64(NSEC_PER_SEC, 64); | |
2199 | /* readahead state */ | 2192 | /* readahead state */ |
2200 | INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT); | 2193 | INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT); |
2201 | spin_lock_init(&fs_info->reada_lock); | 2194 | spin_lock_init(&fs_info->reada_lock); |
@@ -2334,7 +2327,7 @@ int open_ctree(struct super_block *sb, | |||
2334 | * 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). |
2335 | */ | 2328 | */ |
2336 | if (btrfs_check_super_csum(bh->b_data)) { | 2329 | if (btrfs_check_super_csum(bh->b_data)) { |
2337 | printk(KERN_ERR "btrfs: superblock checksum mismatch\n"); | 2330 | printk(KERN_ERR "BTRFS: superblock checksum mismatch\n"); |
2338 | err = -EINVAL; | 2331 | err = -EINVAL; |
2339 | goto fail_alloc; | 2332 | goto fail_alloc; |
2340 | } | 2333 | } |
@@ -2353,7 +2346,7 @@ int open_ctree(struct super_block *sb, | |||
2353 | 2346 | ||
2354 | 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); |
2355 | if (ret) { | 2348 | if (ret) { |
2356 | printk(KERN_ERR "btrfs: superblock contains fatal errors\n"); | 2349 | printk(KERN_ERR "BTRFS: superblock contains fatal errors\n"); |
2357 | err = -EINVAL; | 2350 | err = -EINVAL; |
2358 | goto fail_alloc; | 2351 | goto fail_alloc; |
2359 | } | 2352 | } |
@@ -2418,7 +2411,7 @@ int open_ctree(struct super_block *sb, | |||
2418 | features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO; | 2411 | features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO; |
2419 | 2412 | ||
2420 | if (features & BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA) | 2413 | if (features & BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA) |
2421 | printk(KERN_ERR "btrfs: has skinny extents\n"); | 2414 | printk(KERN_ERR "BTRFS: has skinny extents\n"); |
2422 | 2415 | ||
2423 | /* | 2416 | /* |
2424 | * flag our filesystem as having big metadata blocks if | 2417 | * flag our filesystem as having big metadata blocks if |
@@ -2426,7 +2419,7 @@ int open_ctree(struct super_block *sb, | |||
2426 | */ | 2419 | */ |
2427 | if (btrfs_super_leafsize(disk_super) > PAGE_CACHE_SIZE) { | 2420 | if (btrfs_super_leafsize(disk_super) > PAGE_CACHE_SIZE) { |
2428 | if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA)) | 2421 | if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA)) |
2429 | printk(KERN_INFO "btrfs flagging fs with big metadata feature\n"); | 2422 | printk(KERN_INFO "BTRFS: flagging fs with big metadata feature\n"); |
2430 | features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA; | 2423 | features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA; |
2431 | } | 2424 | } |
2432 | 2425 | ||
@@ -2443,7 +2436,7 @@ int open_ctree(struct super_block *sb, | |||
2443 | */ | 2436 | */ |
2444 | if ((features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) && | 2437 | if ((features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) && |
2445 | (sectorsize != leafsize)) { | 2438 | (sectorsize != leafsize)) { |
2446 | printk(KERN_WARNING "btrfs: unequal leaf/node/sector sizes " | 2439 | printk(KERN_WARNING "BTRFS: unequal leaf/node/sector sizes " |
2447 | "are not allowed for mixed block groups on %s\n", | 2440 | "are not allowed for mixed block groups on %s\n", |
2448 | sb->s_id); | 2441 | sb->s_id); |
2449 | goto fail_alloc; | 2442 | goto fail_alloc; |
@@ -2580,12 +2573,12 @@ int open_ctree(struct super_block *sb, | |||
2580 | sb->s_blocksize_bits = blksize_bits(sectorsize); | 2573 | sb->s_blocksize_bits = blksize_bits(sectorsize); |
2581 | 2574 | ||
2582 | if (btrfs_super_magic(disk_super) != BTRFS_MAGIC) { | 2575 | if (btrfs_super_magic(disk_super) != BTRFS_MAGIC) { |
2583 | 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); |
2584 | goto fail_sb_buffer; | 2577 | goto fail_sb_buffer; |
2585 | } | 2578 | } |
2586 | 2579 | ||
2587 | if (sectorsize != PAGE_SIZE) { | 2580 | if (sectorsize != PAGE_SIZE) { |
2588 | printk(KERN_WARNING "btrfs: Incompatible sector size(%lu) " | 2581 | printk(KERN_WARNING "BTRFS: Incompatible sector size(%lu) " |
2589 | "found on %s\n", (unsigned long)sectorsize, sb->s_id); | 2582 | "found on %s\n", (unsigned long)sectorsize, sb->s_id); |
2590 | goto fail_sb_buffer; | 2583 | goto fail_sb_buffer; |
2591 | } | 2584 | } |
@@ -2594,7 +2587,7 @@ int open_ctree(struct super_block *sb, | |||
2594 | ret = btrfs_read_sys_array(tree_root); | 2587 | ret = btrfs_read_sys_array(tree_root); |
2595 | mutex_unlock(&fs_info->chunk_mutex); | 2588 | mutex_unlock(&fs_info->chunk_mutex); |
2596 | if (ret) { | 2589 | if (ret) { |
2597 | printk(KERN_WARNING "btrfs: failed to read the system " | 2590 | printk(KERN_WARNING "BTRFS: failed to read the system " |
2598 | "array on %s\n", sb->s_id); | 2591 | "array on %s\n", sb->s_id); |
2599 | goto fail_sb_buffer; | 2592 | goto fail_sb_buffer; |
2600 | } | 2593 | } |
@@ -2611,7 +2604,7 @@ int open_ctree(struct super_block *sb, | |||
2611 | blocksize, generation); | 2604 | blocksize, generation); |
2612 | if (!chunk_root->node || | 2605 | if (!chunk_root->node || |
2613 | !test_bit(EXTENT_BUFFER_UPTODATE, &chunk_root->node->bflags)) { | 2606 | !test_bit(EXTENT_BUFFER_UPTODATE, &chunk_root->node->bflags)) { |
2614 | 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", |
2615 | sb->s_id); | 2608 | sb->s_id); |
2616 | goto fail_tree_roots; | 2609 | goto fail_tree_roots; |
2617 | } | 2610 | } |
@@ -2623,7 +2616,7 @@ int open_ctree(struct super_block *sb, | |||
2623 | 2616 | ||
2624 | ret = btrfs_read_chunk_tree(chunk_root); | 2617 | ret = btrfs_read_chunk_tree(chunk_root); |
2625 | if (ret) { | 2618 | if (ret) { |
2626 | 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", |
2627 | sb->s_id); | 2620 | sb->s_id); |
2628 | goto fail_tree_roots; | 2621 | goto fail_tree_roots; |
2629 | } | 2622 | } |
@@ -2635,7 +2628,7 @@ int open_ctree(struct super_block *sb, | |||
2635 | btrfs_close_extra_devices(fs_info, fs_devices, 0); | 2628 | btrfs_close_extra_devices(fs_info, fs_devices, 0); |
2636 | 2629 | ||
2637 | if (!fs_devices->latest_bdev) { | 2630 | if (!fs_devices->latest_bdev) { |
2638 | printk(KERN_CRIT "btrfs: failed to read devices on %s\n", | 2631 | printk(KERN_CRIT "BTRFS: failed to read devices on %s\n", |
2639 | sb->s_id); | 2632 | sb->s_id); |
2640 | goto fail_tree_roots; | 2633 | goto fail_tree_roots; |
2641 | } | 2634 | } |
@@ -2650,7 +2643,7 @@ retry_root_backup: | |||
2650 | blocksize, generation); | 2643 | blocksize, generation); |
2651 | if (!tree_root->node || | 2644 | if (!tree_root->node || |
2652 | !test_bit(EXTENT_BUFFER_UPTODATE, &tree_root->node->bflags)) { | 2645 | !test_bit(EXTENT_BUFFER_UPTODATE, &tree_root->node->bflags)) { |
2653 | 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", |
2654 | sb->s_id); | 2647 | sb->s_id); |
2655 | 2648 | ||
2656 | goto recovery_tree_root; | 2649 | goto recovery_tree_root; |
@@ -2721,50 +2714,56 @@ retry_root_backup: | |||
2721 | 2714 | ||
2722 | ret = btrfs_recover_balance(fs_info); | 2715 | ret = btrfs_recover_balance(fs_info); |
2723 | if (ret) { | 2716 | if (ret) { |
2724 | printk(KERN_WARNING "btrfs: failed to recover balance\n"); | 2717 | printk(KERN_WARNING "BTRFS: failed to recover balance\n"); |
2725 | goto fail_block_groups; | 2718 | goto fail_block_groups; |
2726 | } | 2719 | } |
2727 | 2720 | ||
2728 | ret = btrfs_init_dev_stats(fs_info); | 2721 | ret = btrfs_init_dev_stats(fs_info); |
2729 | if (ret) { | 2722 | if (ret) { |
2730 | printk(KERN_ERR "btrfs: failed to init dev_stats: %d\n", | 2723 | printk(KERN_ERR "BTRFS: failed to init dev_stats: %d\n", |
2731 | ret); | 2724 | ret); |
2732 | goto fail_block_groups; | 2725 | goto fail_block_groups; |
2733 | } | 2726 | } |
2734 | 2727 | ||
2735 | ret = btrfs_init_dev_replace(fs_info); | 2728 | ret = btrfs_init_dev_replace(fs_info); |
2736 | if (ret) { | 2729 | if (ret) { |
2737 | pr_err("btrfs: failed to init dev_replace: %d\n", ret); | 2730 | pr_err("BTRFS: failed to init dev_replace: %d\n", ret); |
2738 | goto fail_block_groups; | 2731 | goto fail_block_groups; |
2739 | } | 2732 | } |
2740 | 2733 | ||
2741 | btrfs_close_extra_devices(fs_info, fs_devices, 1); | 2734 | btrfs_close_extra_devices(fs_info, fs_devices, 1); |
2742 | 2735 | ||
2743 | ret = btrfs_init_space_info(fs_info); | 2736 | ret = btrfs_sysfs_add_one(fs_info); |
2744 | if (ret) { | 2737 | if (ret) { |
2745 | printk(KERN_ERR "Failed to initial space info: %d\n", ret); | 2738 | pr_err("BTRFS: failed to init sysfs interface: %d\n", ret); |
2746 | goto fail_block_groups; | 2739 | goto fail_block_groups; |
2747 | } | 2740 | } |
2748 | 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 | |||
2749 | ret = btrfs_read_block_groups(extent_root); | 2748 | ret = btrfs_read_block_groups(extent_root); |
2750 | if (ret) { | 2749 | if (ret) { |
2751 | printk(KERN_ERR "Failed to read block groups: %d\n", ret); | 2750 | printk(KERN_ERR "BTRFS: Failed to read block groups: %d\n", ret); |
2752 | goto fail_block_groups; | 2751 | goto fail_sysfs; |
2753 | } | 2752 | } |
2754 | fs_info->num_tolerated_disk_barrier_failures = | 2753 | fs_info->num_tolerated_disk_barrier_failures = |
2755 | btrfs_calc_num_tolerated_disk_barrier_failures(fs_info); | 2754 | btrfs_calc_num_tolerated_disk_barrier_failures(fs_info); |
2756 | if (fs_info->fs_devices->missing_devices > | 2755 | if (fs_info->fs_devices->missing_devices > |
2757 | fs_info->num_tolerated_disk_barrier_failures && | 2756 | fs_info->num_tolerated_disk_barrier_failures && |
2758 | !(sb->s_flags & MS_RDONLY)) { | 2757 | !(sb->s_flags & MS_RDONLY)) { |
2759 | printk(KERN_WARNING | 2758 | printk(KERN_WARNING "BTRFS: " |
2760 | "Btrfs: too many missing devices, writeable mount is not allowed\n"); | 2759 | "too many missing devices, writeable mount is not allowed\n"); |
2761 | goto fail_block_groups; | 2760 | goto fail_sysfs; |
2762 | } | 2761 | } |
2763 | 2762 | ||
2764 | fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, | 2763 | fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, |
2765 | "btrfs-cleaner"); | 2764 | "btrfs-cleaner"); |
2766 | if (IS_ERR(fs_info->cleaner_kthread)) | 2765 | if (IS_ERR(fs_info->cleaner_kthread)) |
2767 | goto fail_block_groups; | 2766 | goto fail_sysfs; |
2768 | 2767 | ||
2769 | fs_info->transaction_kthread = kthread_run(transaction_kthread, | 2768 | fs_info->transaction_kthread = kthread_run(transaction_kthread, |
2770 | tree_root, | 2769 | tree_root, |
@@ -2775,11 +2774,15 @@ retry_root_backup: | |||
2775 | if (!btrfs_test_opt(tree_root, SSD) && | 2774 | if (!btrfs_test_opt(tree_root, SSD) && |
2776 | !btrfs_test_opt(tree_root, NOSSD) && | 2775 | !btrfs_test_opt(tree_root, NOSSD) && |
2777 | !fs_info->fs_devices->rotating) { | 2776 | !fs_info->fs_devices->rotating) { |
2778 | printk(KERN_INFO "Btrfs detected SSD devices, enabling SSD " | 2777 | printk(KERN_INFO "BTRFS: detected SSD devices, enabling SSD " |
2779 | "mode\n"); | 2778 | "mode\n"); |
2780 | btrfs_set_opt(fs_info->mount_opt, SSD); | 2779 | btrfs_set_opt(fs_info->mount_opt, SSD); |
2781 | } | 2780 | } |
2782 | 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 | |||
2783 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY | 2786 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY |
2784 | if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) { | 2787 | if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) { |
2785 | ret = btrfsic_mount(tree_root, fs_devices, | 2788 | ret = btrfsic_mount(tree_root, fs_devices, |
@@ -2788,7 +2791,7 @@ retry_root_backup: | |||
2788 | 1 : 0, | 2791 | 1 : 0, |
2789 | fs_info->check_integrity_print_mask); | 2792 | fs_info->check_integrity_print_mask); |
2790 | if (ret) | 2793 | if (ret) |
2791 | printk(KERN_WARNING "btrfs: failed to initialize" | 2794 | printk(KERN_WARNING "BTRFS: failed to initialize" |
2792 | " integrity check module %s\n", sb->s_id); | 2795 | " integrity check module %s\n", sb->s_id); |
2793 | } | 2796 | } |
2794 | #endif | 2797 | #endif |
@@ -2801,7 +2804,7 @@ retry_root_backup: | |||
2801 | u64 bytenr = btrfs_super_log_root(disk_super); | 2804 | u64 bytenr = btrfs_super_log_root(disk_super); |
2802 | 2805 | ||
2803 | if (fs_devices->rw_devices == 0) { | 2806 | if (fs_devices->rw_devices == 0) { |
2804 | printk(KERN_WARNING "Btrfs log replay required " | 2807 | printk(KERN_WARNING "BTRFS: log replay required " |
2805 | "on RO media\n"); | 2808 | "on RO media\n"); |
2806 | err = -EIO; | 2809 | err = -EIO; |
2807 | goto fail_qgroup; | 2810 | goto fail_qgroup; |
@@ -2824,7 +2827,7 @@ retry_root_backup: | |||
2824 | generation + 1); | 2827 | generation + 1); |
2825 | if (!log_tree_root->node || | 2828 | if (!log_tree_root->node || |
2826 | !extent_buffer_uptodate(log_tree_root->node)) { | 2829 | !extent_buffer_uptodate(log_tree_root->node)) { |
2827 | printk(KERN_ERR "btrfs: failed to read log tree\n"); | 2830 | printk(KERN_ERR "BTRFS: failed to read log tree\n"); |
2828 | free_extent_buffer(log_tree_root->node); | 2831 | free_extent_buffer(log_tree_root->node); |
2829 | kfree(log_tree_root); | 2832 | kfree(log_tree_root); |
2830 | goto fail_trans_kthread; | 2833 | goto fail_trans_kthread; |
@@ -2858,7 +2861,7 @@ retry_root_backup: | |||
2858 | ret = btrfs_recover_relocation(tree_root); | 2861 | ret = btrfs_recover_relocation(tree_root); |
2859 | if (ret < 0) { | 2862 | if (ret < 0) { |
2860 | printk(KERN_WARNING | 2863 | printk(KERN_WARNING |
2861 | "btrfs: failed to recover relocation\n"); | 2864 | "BTRFS: failed to recover relocation\n"); |
2862 | err = -EINVAL; | 2865 | err = -EINVAL; |
2863 | goto fail_qgroup; | 2866 | goto fail_qgroup; |
2864 | } | 2867 | } |
@@ -2888,14 +2891,14 @@ retry_root_backup: | |||
2888 | 2891 | ||
2889 | ret = btrfs_resume_balance_async(fs_info); | 2892 | ret = btrfs_resume_balance_async(fs_info); |
2890 | if (ret) { | 2893 | if (ret) { |
2891 | printk(KERN_WARNING "btrfs: failed to resume balance\n"); | 2894 | printk(KERN_WARNING "BTRFS: failed to resume balance\n"); |
2892 | close_ctree(tree_root); | 2895 | close_ctree(tree_root); |
2893 | return ret; | 2896 | return ret; |
2894 | } | 2897 | } |
2895 | 2898 | ||
2896 | ret = btrfs_resume_dev_replace_async(fs_info); | 2899 | ret = btrfs_resume_dev_replace_async(fs_info); |
2897 | if (ret) { | 2900 | if (ret) { |
2898 | pr_warn("btrfs: failed to resume dev_replace\n"); | 2901 | pr_warn("BTRFS: failed to resume dev_replace\n"); |
2899 | close_ctree(tree_root); | 2902 | close_ctree(tree_root); |
2900 | return ret; | 2903 | return ret; |
2901 | } | 2904 | } |
@@ -2903,20 +2906,20 @@ retry_root_backup: | |||
2903 | btrfs_qgroup_rescan_resume(fs_info); | 2906 | btrfs_qgroup_rescan_resume(fs_info); |
2904 | 2907 | ||
2905 | if (create_uuid_tree) { | 2908 | if (create_uuid_tree) { |
2906 | pr_info("btrfs: creating UUID tree\n"); | 2909 | pr_info("BTRFS: creating UUID tree\n"); |
2907 | ret = btrfs_create_uuid_tree(fs_info); | 2910 | ret = btrfs_create_uuid_tree(fs_info); |
2908 | if (ret) { | 2911 | if (ret) { |
2909 | pr_warn("btrfs: failed to create the UUID tree %d\n", | 2912 | pr_warn("BTRFS: failed to create the UUID tree %d\n", |
2910 | ret); | 2913 | ret); |
2911 | close_ctree(tree_root); | 2914 | close_ctree(tree_root); |
2912 | return ret; | 2915 | return ret; |
2913 | } | 2916 | } |
2914 | } else if (check_uuid_tree || | 2917 | } else if (check_uuid_tree || |
2915 | btrfs_test_opt(tree_root, RESCAN_UUID_TREE)) { | 2918 | btrfs_test_opt(tree_root, RESCAN_UUID_TREE)) { |
2916 | pr_info("btrfs: checking UUID tree\n"); | 2919 | pr_info("BTRFS: checking UUID tree\n"); |
2917 | ret = btrfs_check_uuid_tree(fs_info); | 2920 | ret = btrfs_check_uuid_tree(fs_info); |
2918 | if (ret) { | 2921 | if (ret) { |
2919 | pr_warn("btrfs: failed to check the UUID tree %d\n", | 2922 | pr_warn("BTRFS: failed to check the UUID tree %d\n", |
2920 | ret); | 2923 | ret); |
2921 | close_ctree(tree_root); | 2924 | close_ctree(tree_root); |
2922 | return ret; | 2925 | return ret; |
@@ -2942,6 +2945,9 @@ fail_cleaner: | |||
2942 | */ | 2945 | */ |
2943 | filemap_write_and_wait(fs_info->btree_inode->i_mapping); | 2946 | filemap_write_and_wait(fs_info->btree_inode->i_mapping); |
2944 | 2947 | ||
2948 | fail_sysfs: | ||
2949 | btrfs_sysfs_remove_one(fs_info); | ||
2950 | |||
2945 | fail_block_groups: | 2951 | fail_block_groups: |
2946 | btrfs_put_block_group_cache(fs_info); | 2952 | btrfs_put_block_group_cache(fs_info); |
2947 | btrfs_free_block_groups(fs_info); | 2953 | btrfs_free_block_groups(fs_info); |
@@ -2997,7 +3003,7 @@ static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate) | |||
2997 | struct btrfs_device *device = (struct btrfs_device *) | 3003 | struct btrfs_device *device = (struct btrfs_device *) |
2998 | bh->b_private; | 3004 | bh->b_private; |
2999 | 3005 | ||
3000 | printk_ratelimited_in_rcu(KERN_WARNING "lost page write due to " | 3006 | printk_ratelimited_in_rcu(KERN_WARNING "BTRFS: lost page write due to " |
3001 | "I/O error on %s\n", | 3007 | "I/O error on %s\n", |
3002 | rcu_str_deref(device->name)); | 3008 | rcu_str_deref(device->name)); |
3003 | /* note, we dont' set_buffer_write_io_error because we have | 3009 | /* note, we dont' set_buffer_write_io_error because we have |
@@ -3116,7 +3122,7 @@ static int write_dev_supers(struct btrfs_device *device, | |||
3116 | bh = __getblk(device->bdev, bytenr / 4096, | 3122 | bh = __getblk(device->bdev, bytenr / 4096, |
3117 | BTRFS_SUPER_INFO_SIZE); | 3123 | BTRFS_SUPER_INFO_SIZE); |
3118 | if (!bh) { | 3124 | if (!bh) { |
3119 | printk(KERN_ERR "btrfs: couldn't get super " | 3125 | printk(KERN_ERR "BTRFS: couldn't get super " |
3120 | "buffer head for bytenr %Lu\n", bytenr); | 3126 | "buffer head for bytenr %Lu\n", bytenr); |
3121 | errors++; | 3127 | errors++; |
3122 | continue; | 3128 | continue; |
@@ -3137,7 +3143,10 @@ static int write_dev_supers(struct btrfs_device *device, | |||
3137 | * we fua the first super. The others we allow | 3143 | * we fua the first super. The others we allow |
3138 | * to go down lazy. | 3144 | * to go down lazy. |
3139 | */ | 3145 | */ |
3140 | 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); | ||
3141 | if (ret) | 3150 | if (ret) |
3142 | errors++; | 3151 | errors++; |
3143 | } | 3152 | } |
@@ -3183,7 +3192,7 @@ static int write_dev_flush(struct btrfs_device *device, int wait) | |||
3183 | wait_for_completion(&device->flush_wait); | 3192 | wait_for_completion(&device->flush_wait); |
3184 | 3193 | ||
3185 | if (bio_flagged(bio, BIO_EOPNOTSUPP)) { | 3194 | if (bio_flagged(bio, BIO_EOPNOTSUPP)) { |
3186 | printk_in_rcu("btrfs: disabling barriers on dev %s\n", | 3195 | printk_in_rcu("BTRFS: disabling barriers on dev %s\n", |
3187 | rcu_str_deref(device->name)); | 3196 | rcu_str_deref(device->name)); |
3188 | device->nobarriers = 1; | 3197 | device->nobarriers = 1; |
3189 | } else if (!bio_flagged(bio, BIO_UPTODATE)) { | 3198 | } else if (!bio_flagged(bio, BIO_UPTODATE)) { |
@@ -3404,7 +3413,7 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors) | |||
3404 | total_errors++; | 3413 | total_errors++; |
3405 | } | 3414 | } |
3406 | if (total_errors > max_errors) { | 3415 | if (total_errors > max_errors) { |
3407 | printk(KERN_ERR "btrfs: %d errors while writing supers\n", | 3416 | btrfs_err(root->fs_info, "%d errors while writing supers", |
3408 | total_errors); | 3417 | total_errors); |
3409 | mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); | 3418 | mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); |
3410 | 3419 | ||
@@ -3452,10 +3461,8 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, | |||
3452 | if (btrfs_root_refs(&root->root_item) == 0) | 3461 | if (btrfs_root_refs(&root->root_item) == 0) |
3453 | synchronize_srcu(&fs_info->subvol_srcu); | 3462 | synchronize_srcu(&fs_info->subvol_srcu); |
3454 | 3463 | ||
3455 | if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { | 3464 | if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) |
3456 | btrfs_free_log(NULL, root); | 3465 | btrfs_free_log(NULL, root); |
3457 | btrfs_free_log_root_tree(NULL, fs_info); | ||
3458 | } | ||
3459 | 3466 | ||
3460 | __btrfs_remove_free_space_cache(root->free_ino_pinned); | 3467 | __btrfs_remove_free_space_cache(root->free_ino_pinned); |
3461 | __btrfs_remove_free_space_cache(root->free_ino_ctl); | 3468 | __btrfs_remove_free_space_cache(root->free_ino_ctl); |
@@ -3560,14 +3567,12 @@ int close_ctree(struct btrfs_root *root) | |||
3560 | if (!(fs_info->sb->s_flags & MS_RDONLY)) { | 3567 | if (!(fs_info->sb->s_flags & MS_RDONLY)) { |
3561 | ret = btrfs_commit_super(root); | 3568 | ret = btrfs_commit_super(root); |
3562 | if (ret) | 3569 | if (ret) |
3563 | printk(KERN_ERR "btrfs: commit super ret %d\n", ret); | 3570 | btrfs_err(root->fs_info, "commit super ret %d", ret); |
3564 | } | 3571 | } |
3565 | 3572 | ||
3566 | if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) | 3573 | if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) |
3567 | btrfs_error_commit_super(root); | 3574 | btrfs_error_commit_super(root); |
3568 | 3575 | ||
3569 | btrfs_put_block_group_cache(fs_info); | ||
3570 | |||
3571 | kthread_stop(fs_info->transaction_kthread); | 3576 | kthread_stop(fs_info->transaction_kthread); |
3572 | kthread_stop(fs_info->cleaner_kthread); | 3577 | kthread_stop(fs_info->cleaner_kthread); |
3573 | 3578 | ||
@@ -3577,12 +3582,16 @@ int close_ctree(struct btrfs_root *root) | |||
3577 | btrfs_free_qgroup_config(root->fs_info); | 3582 | btrfs_free_qgroup_config(root->fs_info); |
3578 | 3583 | ||
3579 | if (percpu_counter_sum(&fs_info->delalloc_bytes)) { | 3584 | if (percpu_counter_sum(&fs_info->delalloc_bytes)) { |
3580 | printk(KERN_INFO "btrfs: at unmount delalloc count %lld\n", | 3585 | btrfs_info(root->fs_info, "at unmount delalloc count %lld", |
3581 | percpu_counter_sum(&fs_info->delalloc_bytes)); | 3586 | percpu_counter_sum(&fs_info->delalloc_bytes)); |
3582 | } | 3587 | } |
3583 | 3588 | ||
3589 | btrfs_sysfs_remove_one(fs_info); | ||
3590 | |||
3584 | del_fs_roots(fs_info); | 3591 | del_fs_roots(fs_info); |
3585 | 3592 | ||
3593 | btrfs_put_block_group_cache(fs_info); | ||
3594 | |||
3586 | btrfs_free_block_groups(fs_info); | 3595 | btrfs_free_block_groups(fs_info); |
3587 | 3596 | ||
3588 | btrfs_stop_all_workers(fs_info); | 3597 | btrfs_stop_all_workers(fs_info); |
@@ -3800,55 +3809,55 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, | |||
3800 | delayed_refs = &trans->delayed_refs; | 3809 | delayed_refs = &trans->delayed_refs; |
3801 | 3810 | ||
3802 | spin_lock(&delayed_refs->lock); | 3811 | spin_lock(&delayed_refs->lock); |
3803 | if (delayed_refs->num_entries == 0) { | 3812 | if (atomic_read(&delayed_refs->num_entries) == 0) { |
3804 | spin_unlock(&delayed_refs->lock); | 3813 | spin_unlock(&delayed_refs->lock); |
3805 | printk(KERN_INFO "delayed_refs has NO entry\n"); | 3814 | btrfs_info(root->fs_info, "delayed_refs has NO entry"); |
3806 | return ret; | 3815 | return ret; |
3807 | } | 3816 | } |
3808 | 3817 | ||
3809 | while ((node = rb_first(&delayed_refs->root)) != NULL) { | 3818 | while ((node = rb_first(&delayed_refs->href_root)) != NULL) { |
3810 | struct btrfs_delayed_ref_head *head = NULL; | 3819 | struct btrfs_delayed_ref_head *head; |
3811 | bool pin_bytes = false; | 3820 | bool pin_bytes = false; |
3812 | 3821 | ||
3813 | ref = rb_entry(node, struct btrfs_delayed_ref_node, rb_node); | 3822 | head = rb_entry(node, struct btrfs_delayed_ref_head, |
3814 | atomic_set(&ref->refs, 1); | 3823 | href_node); |
3815 | if (btrfs_delayed_ref_is_head(ref)) { | 3824 | if (!mutex_trylock(&head->mutex)) { |
3816 | 3825 | atomic_inc(&head->node.refs); | |
3817 | head = btrfs_delayed_node_to_head(ref); | 3826 | spin_unlock(&delayed_refs->lock); |
3818 | if (!mutex_trylock(&head->mutex)) { | ||
3819 | atomic_inc(&ref->refs); | ||
3820 | spin_unlock(&delayed_refs->lock); | ||
3821 | |||
3822 | /* Need to wait for the delayed ref to run */ | ||
3823 | mutex_lock(&head->mutex); | ||
3824 | mutex_unlock(&head->mutex); | ||
3825 | btrfs_put_delayed_ref(ref); | ||
3826 | |||
3827 | spin_lock(&delayed_refs->lock); | ||
3828 | continue; | ||
3829 | } | ||
3830 | |||
3831 | if (head->must_insert_reserved) | ||
3832 | pin_bytes = true; | ||
3833 | btrfs_free_delayed_extent_op(head->extent_op); | ||
3834 | delayed_refs->num_heads--; | ||
3835 | if (list_empty(&head->cluster)) | ||
3836 | delayed_refs->num_heads_ready--; | ||
3837 | list_del_init(&head->cluster); | ||
3838 | } | ||
3839 | 3827 | ||
3840 | ref->in_tree = 0; | 3828 | mutex_lock(&head->mutex); |
3841 | rb_erase(&ref->rb_node, &delayed_refs->root); | ||
3842 | delayed_refs->num_entries--; | ||
3843 | spin_unlock(&delayed_refs->lock); | ||
3844 | if (head) { | ||
3845 | if (pin_bytes) | ||
3846 | btrfs_pin_extent(root, ref->bytenr, | ||
3847 | ref->num_bytes, 1); | ||
3848 | 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); | ||
3842 | cond_resched_lock(&head->lock); | ||
3849 | } | 3843 | } |
3850 | btrfs_put_delayed_ref(ref); | 3844 | if (head->must_insert_reserved) |
3845 | pin_bytes = true; | ||
3846 | btrfs_free_delayed_extent_op(head->extent_op); | ||
3847 | delayed_refs->num_heads--; | ||
3848 | if (head->processing == 0) | ||
3849 | delayed_refs->num_heads_ready--; | ||
3850 | atomic_dec(&delayed_refs->num_entries); | ||
3851 | head->node.in_tree = 0; | ||
3852 | rb_erase(&head->href_node, &delayed_refs->href_root); | ||
3853 | spin_unlock(&head->lock); | ||
3854 | spin_unlock(&delayed_refs->lock); | ||
3855 | mutex_unlock(&head->mutex); | ||
3851 | 3856 | ||
3857 | if (pin_bytes) | ||
3858 | btrfs_pin_extent(root, head->node.bytenr, | ||
3859 | head->node.num_bytes, 1); | ||
3860 | btrfs_put_delayed_ref(&head->node); | ||
3852 | cond_resched(); | 3861 | cond_resched(); |
3853 | spin_lock(&delayed_refs->lock); | 3862 | spin_lock(&delayed_refs->lock); |
3854 | } | 3863 | } |