aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-10-11 08:03:52 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-11 08:03:52 -0400
commit90d0c376f5ee1927327b267faf15bf970476f09e (patch)
treeb4ed1266ac45a34133e0e93b739067d5f5b33703 /fs/btrfs/disk-io.c
parentac0c49396d5ed9a33f08ce661635ac1bff80bb4f (diff)
parenta43bb39b5c710e79e921fb76341bacc418cfde78 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs updates from Chris Mason: "The largest set of changes here come from Miao Xie. He's cleaning up and improving read recovery/repair for raid, and has a number of related fixes. I've merged another set of fsync fixes from Filipe, and he's also improved the way we handle metadata write errors to make sure we force the FS readonly if things go wrong. Otherwise we have a collection of fixes and cleanups. Dave Sterba gets a cookie for removing the most lines (thanks Dave)" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (139 commits) btrfs: Fix compile error when CONFIG_SECURITY is not set. Btrfs: fix compiles when CONFIG_BTRFS_FS_RUN_SANITY_TESTS is off btrfs: Make btrfs handle security mount options internally to avoid losing security label. Btrfs: send, don't delay dir move if there's a new parent inode btrfs: add more superblock checks Btrfs: fix race in WAIT_SYNC ioctl Btrfs: be aware of btree inode write errors to avoid fs corruption Btrfs: remove redundant btrfs_verify_qgroup_counts declaration. btrfs: fix shadow warning on cmp Btrfs: fix compilation errors under DEBUG Btrfs: fix crash of btrfs_release_extent_buffer_page Btrfs: add missing end_page_writeback on submit_extent_page failure btrfs: Fix the wrong condition judgment about subset extent map Btrfs: fix build_backref_tree issue with multiple shared blocks Btrfs: cleanup error handling in build_backref_tree btrfs: move checks for DUMMY_ROOT into a helper btrfs: new define for the inline extent data start btrfs: kill extent_buffer_page helper btrfs: drop constant param from btrfs_release_extent_buffer_page btrfs: hide typecast to definition of BTRFS_SEND_TRANS_STUB ...
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c284
1 files changed, 173 insertions, 111 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index d0d78dc07792..fa45e3cae40d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -72,21 +72,41 @@ static int btrfs_cleanup_transaction(struct btrfs_root *root);
72static void btrfs_error_commit_super(struct btrfs_root *root); 72static void btrfs_error_commit_super(struct btrfs_root *root);
73 73
74/* 74/*
75 * end_io_wq structs are used to do processing in task context when an IO is 75 * btrfs_end_io_wq structs are used to do processing in task context when an IO
76 * complete. This is used during reads to verify checksums, and it is used 76 * is complete. This is used during reads to verify checksums, and it is used
77 * by writes to insert metadata for new file extents after IO is complete. 77 * by writes to insert metadata for new file extents after IO is complete.
78 */ 78 */
79struct end_io_wq { 79struct btrfs_end_io_wq {
80 struct bio *bio; 80 struct bio *bio;
81 bio_end_io_t *end_io; 81 bio_end_io_t *end_io;
82 void *private; 82 void *private;
83 struct btrfs_fs_info *info; 83 struct btrfs_fs_info *info;
84 int error; 84 int error;
85 int metadata; 85 enum btrfs_wq_endio_type metadata;
86 struct list_head list; 86 struct list_head list;
87 struct btrfs_work work; 87 struct btrfs_work work;
88}; 88};
89 89
90static struct kmem_cache *btrfs_end_io_wq_cache;
91
92int __init btrfs_end_io_wq_init(void)
93{
94 btrfs_end_io_wq_cache = kmem_cache_create("btrfs_end_io_wq",
95 sizeof(struct btrfs_end_io_wq),
96 0,
97 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
98 NULL);
99 if (!btrfs_end_io_wq_cache)
100 return -ENOMEM;
101 return 0;
102}
103
104void btrfs_end_io_wq_exit(void)
105{
106 if (btrfs_end_io_wq_cache)
107 kmem_cache_destroy(btrfs_end_io_wq_cache);
108}
109
90/* 110/*
91 * async submit bios are used to offload expensive checksumming 111 * async submit bios are used to offload expensive checksumming
92 * onto the worker threads. They checksum file and metadata bios 112 * onto the worker threads. They checksum file and metadata bios
@@ -327,8 +347,7 @@ static int verify_parent_transid(struct extent_io_tree *io_tree,
327{ 347{
328 struct extent_state *cached_state = NULL; 348 struct extent_state *cached_state = NULL;
329 int ret; 349 int ret;
330 bool need_lock = (current->journal_info == 350 bool need_lock = (current->journal_info == BTRFS_SEND_TRANS_STUB);
331 (void *)BTRFS_SEND_TRANS_STUB);
332 351
333 if (!parent_transid || btrfs_header_generation(eb) == parent_transid) 352 if (!parent_transid || btrfs_header_generation(eb) == parent_transid)
334 return 0; 353 return 0;
@@ -348,9 +367,9 @@ static int verify_parent_transid(struct extent_io_tree *io_tree,
348 ret = 0; 367 ret = 0;
349 goto out; 368 goto out;
350 } 369 }
351 printk_ratelimited("parent transid verify failed on %llu wanted %llu " 370 printk_ratelimited(KERN_INFO "BTRFS (device %s): parent transid verify failed on %llu wanted %llu found %llu\n",
352 "found %llu\n", 371 eb->fs_info->sb->s_id, eb->start,
353 eb->start, parent_transid, btrfs_header_generation(eb)); 372 parent_transid, btrfs_header_generation(eb));
354 ret = 1; 373 ret = 1;
355 374
356 /* 375 /*
@@ -607,22 +626,22 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,
607 goto err; 626 goto err;
608 627
609 eb->read_mirror = mirror; 628 eb->read_mirror = mirror;
610 if (test_bit(EXTENT_BUFFER_IOERR, &eb->bflags)) { 629 if (test_bit(EXTENT_BUFFER_READ_ERR, &eb->bflags)) {
611 ret = -EIO; 630 ret = -EIO;
612 goto err; 631 goto err;
613 } 632 }
614 633
615 found_start = btrfs_header_bytenr(eb); 634 found_start = btrfs_header_bytenr(eb);
616 if (found_start != eb->start) { 635 if (found_start != eb->start) {
617 printk_ratelimited(KERN_INFO "BTRFS: bad tree block start " 636 printk_ratelimited(KERN_INFO "BTRFS (device %s): bad tree block start "
618 "%llu %llu\n", 637 "%llu %llu\n",
619 found_start, eb->start); 638 eb->fs_info->sb->s_id, found_start, eb->start);
620 ret = -EIO; 639 ret = -EIO;
621 goto err; 640 goto err;
622 } 641 }
623 if (check_tree_block_fsid(root, eb)) { 642 if (check_tree_block_fsid(root, eb)) {
624 printk_ratelimited(KERN_INFO "BTRFS: bad fsid on block %llu\n", 643 printk_ratelimited(KERN_INFO "BTRFS (device %s): bad fsid on block %llu\n",
625 eb->start); 644 eb->fs_info->sb->s_id, eb->start);
626 ret = -EIO; 645 ret = -EIO;
627 goto err; 646 goto err;
628 } 647 }
@@ -680,7 +699,7 @@ static int btree_io_failed_hook(struct page *page, int failed_mirror)
680 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root; 699 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root;
681 700
682 eb = (struct extent_buffer *)page->private; 701 eb = (struct extent_buffer *)page->private;
683 set_bit(EXTENT_BUFFER_IOERR, &eb->bflags); 702 set_bit(EXTENT_BUFFER_READ_ERR, &eb->bflags);
684 eb->read_mirror = failed_mirror; 703 eb->read_mirror = failed_mirror;
685 atomic_dec(&eb->io_pages); 704 atomic_dec(&eb->io_pages);
686 if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags)) 705 if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags))
@@ -690,7 +709,7 @@ static int btree_io_failed_hook(struct page *page, int failed_mirror)
690 709
691static void end_workqueue_bio(struct bio *bio, int err) 710static void end_workqueue_bio(struct bio *bio, int err)
692{ 711{
693 struct end_io_wq *end_io_wq = bio->bi_private; 712 struct btrfs_end_io_wq *end_io_wq = bio->bi_private;
694 struct btrfs_fs_info *fs_info; 713 struct btrfs_fs_info *fs_info;
695 struct btrfs_workqueue *wq; 714 struct btrfs_workqueue *wq;
696 btrfs_work_func_t func; 715 btrfs_work_func_t func;
@@ -713,7 +732,11 @@ static void end_workqueue_bio(struct bio *bio, int err)
713 func = btrfs_endio_write_helper; 732 func = btrfs_endio_write_helper;
714 } 733 }
715 } else { 734 } else {
716 if (end_io_wq->metadata == BTRFS_WQ_ENDIO_RAID56) { 735 if (unlikely(end_io_wq->metadata ==
736 BTRFS_WQ_ENDIO_DIO_REPAIR)) {
737 wq = fs_info->endio_repair_workers;
738 func = btrfs_endio_repair_helper;
739 } else if (end_io_wq->metadata == BTRFS_WQ_ENDIO_RAID56) {
717 wq = fs_info->endio_raid56_workers; 740 wq = fs_info->endio_raid56_workers;
718 func = btrfs_endio_raid56_helper; 741 func = btrfs_endio_raid56_helper;
719 } else if (end_io_wq->metadata) { 742 } else if (end_io_wq->metadata) {
@@ -729,19 +752,12 @@ static void end_workqueue_bio(struct bio *bio, int err)
729 btrfs_queue_work(wq, &end_io_wq->work); 752 btrfs_queue_work(wq, &end_io_wq->work);
730} 753}
731 754
732/*
733 * For the metadata arg you want
734 *
735 * 0 - if data
736 * 1 - if normal metadta
737 * 2 - if writing to the free space cache area
738 * 3 - raid parity work
739 */
740int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio, 755int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio,
741 int metadata) 756 enum btrfs_wq_endio_type metadata)
742{ 757{
743 struct end_io_wq *end_io_wq; 758 struct btrfs_end_io_wq *end_io_wq;
744 end_io_wq = kmalloc(sizeof(*end_io_wq), GFP_NOFS); 759
760 end_io_wq = kmem_cache_alloc(btrfs_end_io_wq_cache, GFP_NOFS);
745 if (!end_io_wq) 761 if (!end_io_wq)
746 return -ENOMEM; 762 return -ENOMEM;
747 763
@@ -925,7 +941,7 @@ static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
925 * can happen in the async kernel threads 941 * can happen in the async kernel threads
926 */ 942 */
927 ret = btrfs_bio_wq_end_io(BTRFS_I(inode)->root->fs_info, 943 ret = btrfs_bio_wq_end_io(BTRFS_I(inode)->root->fs_info,
928 bio, 1); 944 bio, BTRFS_WQ_ENDIO_METADATA);
929 if (ret) 945 if (ret)
930 goto out_w_error; 946 goto out_w_error;
931 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, 947 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio,
@@ -1057,20 +1073,17 @@ static const struct address_space_operations btree_aops = {
1057 .set_page_dirty = btree_set_page_dirty, 1073 .set_page_dirty = btree_set_page_dirty,
1058}; 1074};
1059 1075
1060int readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize, 1076void readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize)
1061 u64 parent_transid)
1062{ 1077{
1063 struct extent_buffer *buf = NULL; 1078 struct extent_buffer *buf = NULL;
1064 struct inode *btree_inode = root->fs_info->btree_inode; 1079 struct inode *btree_inode = root->fs_info->btree_inode;
1065 int ret = 0;
1066 1080
1067 buf = btrfs_find_create_tree_block(root, bytenr, blocksize); 1081 buf = btrfs_find_create_tree_block(root, bytenr, blocksize);
1068 if (!buf) 1082 if (!buf)
1069 return 0; 1083 return;
1070 read_extent_buffer_pages(&BTRFS_I(btree_inode)->io_tree, 1084 read_extent_buffer_pages(&BTRFS_I(btree_inode)->io_tree,
1071 buf, 0, WAIT_NONE, btree_get_extent, 0); 1085 buf, 0, WAIT_NONE, btree_get_extent, 0);
1072 free_extent_buffer(buf); 1086 free_extent_buffer(buf);
1073 return ret;
1074} 1087}
1075 1088
1076int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, u32 blocksize, 1089int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, u32 blocksize,
@@ -1106,7 +1119,7 @@ int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, u32 blocksize,
1106} 1119}
1107 1120
1108struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root, 1121struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
1109 u64 bytenr, u32 blocksize) 1122 u64 bytenr)
1110{ 1123{
1111 return find_extent_buffer(root->fs_info, bytenr); 1124 return find_extent_buffer(root->fs_info, bytenr);
1112} 1125}
@@ -1114,11 +1127,9 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
1114struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, 1127struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
1115 u64 bytenr, u32 blocksize) 1128 u64 bytenr, u32 blocksize)
1116{ 1129{
1117#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 1130 if (btrfs_test_is_dummy_root(root))
1118 if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state)))
1119 return alloc_test_extent_buffer(root->fs_info, bytenr, 1131 return alloc_test_extent_buffer(root->fs_info, bytenr,
1120 blocksize); 1132 blocksize);
1121#endif
1122 return alloc_extent_buffer(root->fs_info, bytenr, blocksize); 1133 return alloc_extent_buffer(root->fs_info, bytenr, blocksize);
1123} 1134}
1124 1135
@@ -1136,12 +1147,12 @@ int btrfs_wait_tree_block_writeback(struct extent_buffer *buf)
1136} 1147}
1137 1148
1138struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr, 1149struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
1139 u32 blocksize, u64 parent_transid) 1150 u64 parent_transid)
1140{ 1151{
1141 struct extent_buffer *buf = NULL; 1152 struct extent_buffer *buf = NULL;
1142 int ret; 1153 int ret;
1143 1154
1144 buf = btrfs_find_create_tree_block(root, bytenr, blocksize); 1155 buf = btrfs_find_create_tree_block(root, bytenr, root->nodesize);
1145 if (!buf) 1156 if (!buf)
1146 return NULL; 1157 return NULL;
1147 1158
@@ -1200,16 +1211,14 @@ btrfs_free_subvolume_writers(struct btrfs_subvolume_writers *writers)
1200 kfree(writers); 1211 kfree(writers);
1201} 1212}
1202 1213
1203static void __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, 1214static void __setup_root(u32 nodesize, u32 sectorsize, u32 stripesize,
1204 u32 stripesize, struct btrfs_root *root, 1215 struct btrfs_root *root, struct btrfs_fs_info *fs_info,
1205 struct btrfs_fs_info *fs_info,
1206 u64 objectid) 1216 u64 objectid)
1207{ 1217{
1208 root->node = NULL; 1218 root->node = NULL;
1209 root->commit_root = NULL; 1219 root->commit_root = NULL;
1210 root->sectorsize = sectorsize; 1220 root->sectorsize = sectorsize;
1211 root->nodesize = nodesize; 1221 root->nodesize = nodesize;
1212 root->leafsize = leafsize;
1213 root->stripesize = stripesize; 1222 root->stripesize = stripesize;
1214 root->state = 0; 1223 root->state = 0;
1215 root->orphan_cleanup_state = 0; 1224 root->orphan_cleanup_state = 0;
@@ -1295,7 +1304,7 @@ struct btrfs_root *btrfs_alloc_dummy_root(void)
1295 root = btrfs_alloc_root(NULL); 1304 root = btrfs_alloc_root(NULL);
1296 if (!root) 1305 if (!root)
1297 return ERR_PTR(-ENOMEM); 1306 return ERR_PTR(-ENOMEM);
1298 __setup_root(4096, 4096, 4096, 4096, root, NULL, 1); 1307 __setup_root(4096, 4096, 4096, root, NULL, 1);
1299 set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state); 1308 set_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state);
1300 root->alloc_bytenr = 0; 1309 root->alloc_bytenr = 0;
1301 1310
@@ -1318,15 +1327,13 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
1318 if (!root) 1327 if (!root)
1319 return ERR_PTR(-ENOMEM); 1328 return ERR_PTR(-ENOMEM);
1320 1329
1321 __setup_root(tree_root->nodesize, tree_root->leafsize, 1330 __setup_root(tree_root->nodesize, tree_root->sectorsize,
1322 tree_root->sectorsize, tree_root->stripesize, 1331 tree_root->stripesize, root, fs_info, objectid);
1323 root, fs_info, objectid);
1324 root->root_key.objectid = objectid; 1332 root->root_key.objectid = objectid;
1325 root->root_key.type = BTRFS_ROOT_ITEM_KEY; 1333 root->root_key.type = BTRFS_ROOT_ITEM_KEY;
1326 root->root_key.offset = 0; 1334 root->root_key.offset = 0;
1327 1335
1328 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 1336 leaf = btrfs_alloc_tree_block(trans, root, 0, objectid, NULL, 0, 0, 0);
1329 0, objectid, NULL, 0, 0, 0);
1330 if (IS_ERR(leaf)) { 1337 if (IS_ERR(leaf)) {
1331 ret = PTR_ERR(leaf); 1338 ret = PTR_ERR(leaf);
1332 leaf = NULL; 1339 leaf = NULL;
@@ -1396,9 +1403,9 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1396 if (!root) 1403 if (!root)
1397 return ERR_PTR(-ENOMEM); 1404 return ERR_PTR(-ENOMEM);
1398 1405
1399 __setup_root(tree_root->nodesize, tree_root->leafsize, 1406 __setup_root(tree_root->nodesize, tree_root->sectorsize,
1400 tree_root->sectorsize, tree_root->stripesize, 1407 tree_root->stripesize, root, fs_info,
1401 root, fs_info, BTRFS_TREE_LOG_OBJECTID); 1408 BTRFS_TREE_LOG_OBJECTID);
1402 1409
1403 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID; 1410 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID;
1404 root->root_key.type = BTRFS_ROOT_ITEM_KEY; 1411 root->root_key.type = BTRFS_ROOT_ITEM_KEY;
@@ -1413,9 +1420,8 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1413 * updated (along with back refs to the log tree). 1420 * updated (along with back refs to the log tree).
1414 */ 1421 */
1415 1422
1416 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 0, 1423 leaf = btrfs_alloc_tree_block(trans, root, 0, BTRFS_TREE_LOG_OBJECTID,
1417 BTRFS_TREE_LOG_OBJECTID, NULL, 1424 NULL, 0, 0, 0);
1418 0, 0, 0);
1419 if (IS_ERR(leaf)) { 1425 if (IS_ERR(leaf)) {
1420 kfree(root); 1426 kfree(root);
1421 return ERR_CAST(leaf); 1427 return ERR_CAST(leaf);
@@ -1465,7 +1471,7 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
1465 btrfs_set_stack_inode_generation(inode_item, 1); 1471 btrfs_set_stack_inode_generation(inode_item, 1);
1466 btrfs_set_stack_inode_size(inode_item, 3); 1472 btrfs_set_stack_inode_size(inode_item, 3);
1467 btrfs_set_stack_inode_nlink(inode_item, 1); 1473 btrfs_set_stack_inode_nlink(inode_item, 1);
1468 btrfs_set_stack_inode_nbytes(inode_item, root->leafsize); 1474 btrfs_set_stack_inode_nbytes(inode_item, root->nodesize);
1469 btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755); 1475 btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755);
1470 1476
1471 btrfs_set_root_node(&log_root->root_item, log_root->node); 1477 btrfs_set_root_node(&log_root->root_item, log_root->node);
@@ -1485,7 +1491,6 @@ static struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
1485 struct btrfs_fs_info *fs_info = tree_root->fs_info; 1491 struct btrfs_fs_info *fs_info = tree_root->fs_info;
1486 struct btrfs_path *path; 1492 struct btrfs_path *path;
1487 u64 generation; 1493 u64 generation;
1488 u32 blocksize;
1489 int ret; 1494 int ret;
1490 1495
1491 path = btrfs_alloc_path(); 1496 path = btrfs_alloc_path();
@@ -1498,9 +1503,8 @@ static struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
1498 goto alloc_fail; 1503 goto alloc_fail;
1499 } 1504 }
1500 1505
1501 __setup_root(tree_root->nodesize, tree_root->leafsize, 1506 __setup_root(tree_root->nodesize, tree_root->sectorsize,
1502 tree_root->sectorsize, tree_root->stripesize, 1507 tree_root->stripesize, root, fs_info, key->objectid);
1503 root, fs_info, key->objectid);
1504 1508
1505 ret = btrfs_find_root(tree_root, key, path, 1509 ret = btrfs_find_root(tree_root, key, path,
1506 &root->root_item, &root->root_key); 1510 &root->root_item, &root->root_key);
@@ -1511,9 +1515,8 @@ static struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
1511 } 1515 }
1512 1516
1513 generation = btrfs_root_generation(&root->root_item); 1517 generation = btrfs_root_generation(&root->root_item);
1514 blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item));
1515 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), 1518 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item),
1516 blocksize, generation); 1519 generation);
1517 if (!root->node) { 1520 if (!root->node) {
1518 ret = -ENOMEM; 1521 ret = -ENOMEM;
1519 goto find_fail; 1522 goto find_fail;
@@ -1573,8 +1576,8 @@ int btrfs_init_fs_root(struct btrfs_root *root)
1573 root->subv_writers = writers; 1576 root->subv_writers = writers;
1574 1577
1575 btrfs_init_free_ino_ctl(root); 1578 btrfs_init_free_ino_ctl(root);
1576 spin_lock_init(&root->cache_lock); 1579 spin_lock_init(&root->ino_cache_lock);
1577 init_waitqueue_head(&root->cache_wait); 1580 init_waitqueue_head(&root->ino_cache_wait);
1578 1581
1579 ret = get_anon_bdev(&root->anon_dev); 1582 ret = get_anon_bdev(&root->anon_dev);
1580 if (ret) 1583 if (ret)
@@ -1708,10 +1711,6 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
1708 return ret; 1711 return ret;
1709} 1712}
1710 1713
1711/*
1712 * If this fails, caller must call bdi_destroy() to get rid of the
1713 * bdi again.
1714 */
1715static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi) 1714static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi)
1716{ 1715{
1717 int err; 1716 int err;
@@ -1734,16 +1733,16 @@ static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi)
1734static void end_workqueue_fn(struct btrfs_work *work) 1733static void end_workqueue_fn(struct btrfs_work *work)
1735{ 1734{
1736 struct bio *bio; 1735 struct bio *bio;
1737 struct end_io_wq *end_io_wq; 1736 struct btrfs_end_io_wq *end_io_wq;
1738 int error; 1737 int error;
1739 1738
1740 end_io_wq = container_of(work, struct end_io_wq, work); 1739 end_io_wq = container_of(work, struct btrfs_end_io_wq, work);
1741 bio = end_io_wq->bio; 1740 bio = end_io_wq->bio;
1742 1741
1743 error = end_io_wq->error; 1742 error = end_io_wq->error;
1744 bio->bi_private = end_io_wq->private; 1743 bio->bi_private = end_io_wq->private;
1745 bio->bi_end_io = end_io_wq->end_io; 1744 bio->bi_end_io = end_io_wq->end_io;
1746 kfree(end_io_wq); 1745 kmem_cache_free(btrfs_end_io_wq_cache, end_io_wq);
1747 bio_endio_nodec(bio, error); 1746 bio_endio_nodec(bio, error);
1748} 1747}
1749 1748
@@ -1772,6 +1771,7 @@ static int cleaner_kthread(void *arg)
1772 } 1771 }
1773 1772
1774 btrfs_run_delayed_iputs(root); 1773 btrfs_run_delayed_iputs(root);
1774 btrfs_delete_unused_bgs(root->fs_info);
1775 again = btrfs_clean_one_deleted_snapshot(root); 1775 again = btrfs_clean_one_deleted_snapshot(root);
1776 mutex_unlock(&root->fs_info->cleaner_mutex); 1776 mutex_unlock(&root->fs_info->cleaner_mutex);
1777 1777
@@ -2063,6 +2063,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
2063 btrfs_destroy_workqueue(fs_info->endio_workers); 2063 btrfs_destroy_workqueue(fs_info->endio_workers);
2064 btrfs_destroy_workqueue(fs_info->endio_meta_workers); 2064 btrfs_destroy_workqueue(fs_info->endio_meta_workers);
2065 btrfs_destroy_workqueue(fs_info->endio_raid56_workers); 2065 btrfs_destroy_workqueue(fs_info->endio_raid56_workers);
2066 btrfs_destroy_workqueue(fs_info->endio_repair_workers);
2066 btrfs_destroy_workqueue(fs_info->rmw_workers); 2067 btrfs_destroy_workqueue(fs_info->rmw_workers);
2067 btrfs_destroy_workqueue(fs_info->endio_meta_write_workers); 2068 btrfs_destroy_workqueue(fs_info->endio_meta_write_workers);
2068 btrfs_destroy_workqueue(fs_info->endio_write_workers); 2069 btrfs_destroy_workqueue(fs_info->endio_write_workers);
@@ -2143,8 +2144,6 @@ int open_ctree(struct super_block *sb,
2143{ 2144{
2144 u32 sectorsize; 2145 u32 sectorsize;
2145 u32 nodesize; 2146 u32 nodesize;
2146 u32 leafsize;
2147 u32 blocksize;
2148 u32 stripesize; 2147 u32 stripesize;
2149 u64 generation; 2148 u64 generation;
2150 u64 features; 2149 u64 features;
@@ -2233,6 +2232,7 @@ int open_ctree(struct super_block *sb,
2233 spin_lock_init(&fs_info->super_lock); 2232 spin_lock_init(&fs_info->super_lock);
2234 spin_lock_init(&fs_info->qgroup_op_lock); 2233 spin_lock_init(&fs_info->qgroup_op_lock);
2235 spin_lock_init(&fs_info->buffer_lock); 2234 spin_lock_init(&fs_info->buffer_lock);
2235 spin_lock_init(&fs_info->unused_bgs_lock);
2236 rwlock_init(&fs_info->tree_mod_log_lock); 2236 rwlock_init(&fs_info->tree_mod_log_lock);
2237 mutex_init(&fs_info->reloc_mutex); 2237 mutex_init(&fs_info->reloc_mutex);
2238 mutex_init(&fs_info->delalloc_root_mutex); 2238 mutex_init(&fs_info->delalloc_root_mutex);
@@ -2242,6 +2242,7 @@ int open_ctree(struct super_block *sb,
2242 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); 2242 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots);
2243 INIT_LIST_HEAD(&fs_info->space_info); 2243 INIT_LIST_HEAD(&fs_info->space_info);
2244 INIT_LIST_HEAD(&fs_info->tree_mod_seq_list); 2244 INIT_LIST_HEAD(&fs_info->tree_mod_seq_list);
2245 INIT_LIST_HEAD(&fs_info->unused_bgs);
2245 btrfs_mapping_init(&fs_info->mapping_tree); 2246 btrfs_mapping_init(&fs_info->mapping_tree);
2246 btrfs_init_block_rsv(&fs_info->global_block_rsv, 2247 btrfs_init_block_rsv(&fs_info->global_block_rsv,
2247 BTRFS_BLOCK_RSV_GLOBAL); 2248 BTRFS_BLOCK_RSV_GLOBAL);
@@ -2260,7 +2261,7 @@ int open_ctree(struct super_block *sb,
2260 atomic_set(&fs_info->qgroup_op_seq, 0); 2261 atomic_set(&fs_info->qgroup_op_seq, 0);
2261 atomic64_set(&fs_info->tree_mod_seq, 0); 2262 atomic64_set(&fs_info->tree_mod_seq, 0);
2262 fs_info->sb = sb; 2263 fs_info->sb = sb;
2263 fs_info->max_inline = 8192 * 1024; 2264 fs_info->max_inline = BTRFS_DEFAULT_MAX_INLINE;
2264 fs_info->metadata_ratio = 0; 2265 fs_info->metadata_ratio = 0;
2265 fs_info->defrag_inodes = RB_ROOT; 2266 fs_info->defrag_inodes = RB_ROOT;
2266 fs_info->free_chunk_space = 0; 2267 fs_info->free_chunk_space = 0;
@@ -2389,7 +2390,7 @@ int open_ctree(struct super_block *sb,
2389 goto fail_alloc; 2390 goto fail_alloc;
2390 } 2391 }
2391 2392
2392 __setup_root(4096, 4096, 4096, 4096, tree_root, 2393 __setup_root(4096, 4096, 4096, tree_root,
2393 fs_info, BTRFS_ROOT_TREE_OBJECTID); 2394 fs_info, BTRFS_ROOT_TREE_OBJECTID);
2394 2395
2395 invalidate_bdev(fs_devices->latest_bdev); 2396 invalidate_bdev(fs_devices->latest_bdev);
@@ -2469,19 +2470,22 @@ int open_ctree(struct super_block *sb,
2469 goto fail_alloc; 2470 goto fail_alloc;
2470 } 2471 }
2471 2472
2472 if (btrfs_super_leafsize(disk_super) != 2473 /*
2474 * Leafsize and nodesize were always equal, this is only a sanity check.
2475 */
2476 if (le32_to_cpu(disk_super->__unused_leafsize) !=
2473 btrfs_super_nodesize(disk_super)) { 2477 btrfs_super_nodesize(disk_super)) {
2474 printk(KERN_ERR "BTRFS: couldn't mount because metadata " 2478 printk(KERN_ERR "BTRFS: couldn't mount because metadata "
2475 "blocksizes don't match. node %d leaf %d\n", 2479 "blocksizes don't match. node %d leaf %d\n",
2476 btrfs_super_nodesize(disk_super), 2480 btrfs_super_nodesize(disk_super),
2477 btrfs_super_leafsize(disk_super)); 2481 le32_to_cpu(disk_super->__unused_leafsize));
2478 err = -EINVAL; 2482 err = -EINVAL;
2479 goto fail_alloc; 2483 goto fail_alloc;
2480 } 2484 }
2481 if (btrfs_super_leafsize(disk_super) > BTRFS_MAX_METADATA_BLOCKSIZE) { 2485 if (btrfs_super_nodesize(disk_super) > BTRFS_MAX_METADATA_BLOCKSIZE) {
2482 printk(KERN_ERR "BTRFS: couldn't mount because metadata " 2486 printk(KERN_ERR "BTRFS: couldn't mount because metadata "
2483 "blocksize (%d) was too large\n", 2487 "blocksize (%d) was too large\n",
2484 btrfs_super_leafsize(disk_super)); 2488 btrfs_super_nodesize(disk_super));
2485 err = -EINVAL; 2489 err = -EINVAL;
2486 goto fail_alloc; 2490 goto fail_alloc;
2487 } 2491 }
@@ -2498,17 +2502,16 @@ int open_ctree(struct super_block *sb,
2498 * flag our filesystem as having big metadata blocks if 2502 * flag our filesystem as having big metadata blocks if
2499 * they are bigger than the page size 2503 * they are bigger than the page size
2500 */ 2504 */
2501 if (btrfs_super_leafsize(disk_super) > PAGE_CACHE_SIZE) { 2505 if (btrfs_super_nodesize(disk_super) > PAGE_CACHE_SIZE) {
2502 if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA)) 2506 if (!(features & BTRFS_FEATURE_INCOMPAT_BIG_METADATA))
2503 printk(KERN_INFO "BTRFS: flagging fs with big metadata feature\n"); 2507 printk(KERN_INFO "BTRFS: flagging fs with big metadata feature\n");
2504 features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA; 2508 features |= BTRFS_FEATURE_INCOMPAT_BIG_METADATA;
2505 } 2509 }
2506 2510
2507 nodesize = btrfs_super_nodesize(disk_super); 2511 nodesize = btrfs_super_nodesize(disk_super);
2508 leafsize = btrfs_super_leafsize(disk_super);
2509 sectorsize = btrfs_super_sectorsize(disk_super); 2512 sectorsize = btrfs_super_sectorsize(disk_super);
2510 stripesize = btrfs_super_stripesize(disk_super); 2513 stripesize = btrfs_super_stripesize(disk_super);
2511 fs_info->dirty_metadata_batch = leafsize * (1 + ilog2(nr_cpu_ids)); 2514 fs_info->dirty_metadata_batch = nodesize * (1 + ilog2(nr_cpu_ids));
2512 fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids)); 2515 fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids));
2513 2516
2514 /* 2517 /*
@@ -2516,7 +2519,7 @@ int open_ctree(struct super_block *sb,
2516 * extent buffers for the same range. It leads to corruptions 2519 * extent buffers for the same range. It leads to corruptions
2517 */ 2520 */
2518 if ((features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) && 2521 if ((features & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) &&
2519 (sectorsize != leafsize)) { 2522 (sectorsize != nodesize)) {
2520 printk(KERN_WARNING "BTRFS: unequal leaf/node/sector sizes " 2523 printk(KERN_WARNING "BTRFS: unequal leaf/node/sector sizes "
2521 "are not allowed for mixed block groups on %s\n", 2524 "are not allowed for mixed block groups on %s\n",
2522 sb->s_id); 2525 sb->s_id);
@@ -2579,6 +2582,8 @@ int open_ctree(struct super_block *sb,
2579 btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2); 2582 btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2);
2580 fs_info->endio_raid56_workers = 2583 fs_info->endio_raid56_workers =
2581 btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4); 2584 btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4);
2585 fs_info->endio_repair_workers =
2586 btrfs_alloc_workqueue("endio-repair", flags, 1, 0);
2582 fs_info->rmw_workers = 2587 fs_info->rmw_workers =
2583 btrfs_alloc_workqueue("rmw", flags, max_active, 2); 2588 btrfs_alloc_workqueue("rmw", flags, max_active, 2);
2584 fs_info->endio_write_workers = 2589 fs_info->endio_write_workers =
@@ -2600,11 +2605,12 @@ int open_ctree(struct super_block *sb,
2600 fs_info->submit_workers && fs_info->flush_workers && 2605 fs_info->submit_workers && fs_info->flush_workers &&
2601 fs_info->endio_workers && fs_info->endio_meta_workers && 2606 fs_info->endio_workers && fs_info->endio_meta_workers &&
2602 fs_info->endio_meta_write_workers && 2607 fs_info->endio_meta_write_workers &&
2608 fs_info->endio_repair_workers &&
2603 fs_info->endio_write_workers && fs_info->endio_raid56_workers && 2609 fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
2604 fs_info->endio_freespace_worker && fs_info->rmw_workers && 2610 fs_info->endio_freespace_worker && fs_info->rmw_workers &&
2605 fs_info->caching_workers && fs_info->readahead_workers && 2611 fs_info->caching_workers && fs_info->readahead_workers &&
2606 fs_info->fixup_workers && fs_info->delayed_workers && 2612 fs_info->fixup_workers && fs_info->delayed_workers &&
2607 fs_info->fixup_workers && fs_info->extent_workers && 2613 fs_info->extent_workers &&
2608 fs_info->qgroup_rescan_workers)) { 2614 fs_info->qgroup_rescan_workers)) {
2609 err = -ENOMEM; 2615 err = -ENOMEM;
2610 goto fail_sb_buffer; 2616 goto fail_sb_buffer;
@@ -2615,7 +2621,6 @@ int open_ctree(struct super_block *sb,
2615 4 * 1024 * 1024 / PAGE_CACHE_SIZE); 2621 4 * 1024 * 1024 / PAGE_CACHE_SIZE);
2616 2622
2617 tree_root->nodesize = nodesize; 2623 tree_root->nodesize = nodesize;
2618 tree_root->leafsize = leafsize;
2619 tree_root->sectorsize = sectorsize; 2624 tree_root->sectorsize = sectorsize;
2620 tree_root->stripesize = stripesize; 2625 tree_root->stripesize = stripesize;
2621 2626
@@ -2642,16 +2647,14 @@ int open_ctree(struct super_block *sb,
2642 goto fail_sb_buffer; 2647 goto fail_sb_buffer;
2643 } 2648 }
2644 2649
2645 blocksize = btrfs_level_size(tree_root,
2646 btrfs_super_chunk_root_level(disk_super));
2647 generation = btrfs_super_chunk_root_generation(disk_super); 2650 generation = btrfs_super_chunk_root_generation(disk_super);
2648 2651
2649 __setup_root(nodesize, leafsize, sectorsize, stripesize, 2652 __setup_root(nodesize, sectorsize, stripesize, chunk_root,
2650 chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID); 2653 fs_info, BTRFS_CHUNK_TREE_OBJECTID);
2651 2654
2652 chunk_root->node = read_tree_block(chunk_root, 2655 chunk_root->node = read_tree_block(chunk_root,
2653 btrfs_super_chunk_root(disk_super), 2656 btrfs_super_chunk_root(disk_super),
2654 blocksize, generation); 2657 generation);
2655 if (!chunk_root->node || 2658 if (!chunk_root->node ||
2656 !test_bit(EXTENT_BUFFER_UPTODATE, &chunk_root->node->bflags)) { 2659 !test_bit(EXTENT_BUFFER_UPTODATE, &chunk_root->node->bflags)) {
2657 printk(KERN_WARNING "BTRFS: failed to read chunk root on %s\n", 2660 printk(KERN_WARNING "BTRFS: failed to read chunk root on %s\n",
@@ -2684,13 +2687,11 @@ int open_ctree(struct super_block *sb,
2684 } 2687 }
2685 2688
2686retry_root_backup: 2689retry_root_backup:
2687 blocksize = btrfs_level_size(tree_root,
2688 btrfs_super_root_level(disk_super));
2689 generation = btrfs_super_generation(disk_super); 2690 generation = btrfs_super_generation(disk_super);
2690 2691
2691 tree_root->node = read_tree_block(tree_root, 2692 tree_root->node = read_tree_block(tree_root,
2692 btrfs_super_root(disk_super), 2693 btrfs_super_root(disk_super),
2693 blocksize, generation); 2694 generation);
2694 if (!tree_root->node || 2695 if (!tree_root->node ||
2695 !test_bit(EXTENT_BUFFER_UPTODATE, &tree_root->node->bflags)) { 2696 !test_bit(EXTENT_BUFFER_UPTODATE, &tree_root->node->bflags)) {
2696 printk(KERN_WARNING "BTRFS: failed to read tree root on %s\n", 2697 printk(KERN_WARNING "BTRFS: failed to read tree root on %s\n",
@@ -2859,9 +2860,6 @@ retry_root_backup:
2859 err = -EIO; 2860 err = -EIO;
2860 goto fail_qgroup; 2861 goto fail_qgroup;
2861 } 2862 }
2862 blocksize =
2863 btrfs_level_size(tree_root,
2864 btrfs_super_log_root_level(disk_super));
2865 2863
2866 log_tree_root = btrfs_alloc_root(fs_info); 2864 log_tree_root = btrfs_alloc_root(fs_info);
2867 if (!log_tree_root) { 2865 if (!log_tree_root) {
@@ -2869,11 +2867,10 @@ retry_root_backup:
2869 goto fail_qgroup; 2867 goto fail_qgroup;
2870 } 2868 }
2871 2869
2872 __setup_root(nodesize, leafsize, sectorsize, stripesize, 2870 __setup_root(nodesize, sectorsize, stripesize,
2873 log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID); 2871 log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID);
2874 2872
2875 log_tree_root->node = read_tree_block(tree_root, bytenr, 2873 log_tree_root->node = read_tree_block(tree_root, bytenr,
2876 blocksize,
2877 generation + 1); 2874 generation + 1);
2878 if (!log_tree_root->node || 2875 if (!log_tree_root->node ||
2879 !extent_buffer_uptodate(log_tree_root->node)) { 2876 !extent_buffer_uptodate(log_tree_root->node)) {
@@ -2980,6 +2977,8 @@ retry_root_backup:
2980 fs_info->update_uuid_tree_gen = 1; 2977 fs_info->update_uuid_tree_gen = 1;
2981 } 2978 }
2982 2979
2980 fs_info->open = 1;
2981
2983 return 0; 2982 return 0;
2984 2983
2985fail_qgroup: 2984fail_qgroup:
@@ -3139,7 +3138,8 @@ static int write_dev_supers(struct btrfs_device *device,
3139 3138
3140 for (i = 0; i < max_mirrors; i++) { 3139 for (i = 0; i < max_mirrors; i++) {
3141 bytenr = btrfs_sb_offset(i); 3140 bytenr = btrfs_sb_offset(i);
3142 if (bytenr + BTRFS_SUPER_INFO_SIZE >= device->total_bytes) 3141 if (bytenr + BTRFS_SUPER_INFO_SIZE >=
3142 device->commit_total_bytes)
3143 break; 3143 break;
3144 3144
3145 if (wait) { 3145 if (wait) {
@@ -3456,8 +3456,9 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors)
3456 btrfs_set_stack_device_type(dev_item, dev->type); 3456 btrfs_set_stack_device_type(dev_item, dev->type);
3457 btrfs_set_stack_device_id(dev_item, dev->devid); 3457 btrfs_set_stack_device_id(dev_item, dev->devid);
3458 btrfs_set_stack_device_total_bytes(dev_item, 3458 btrfs_set_stack_device_total_bytes(dev_item,
3459 dev->disk_total_bytes); 3459 dev->commit_total_bytes);
3460 btrfs_set_stack_device_bytes_used(dev_item, dev->bytes_used); 3460 btrfs_set_stack_device_bytes_used(dev_item,
3461 dev->commit_bytes_used);
3461 btrfs_set_stack_device_io_align(dev_item, dev->io_align); 3462 btrfs_set_stack_device_io_align(dev_item, dev->io_align);
3462 btrfs_set_stack_device_io_width(dev_item, dev->io_width); 3463 btrfs_set_stack_device_io_width(dev_item, dev->io_width);
3463 btrfs_set_stack_device_sector_size(dev_item, dev->sector_size); 3464 btrfs_set_stack_device_sector_size(dev_item, dev->sector_size);
@@ -3532,7 +3533,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
3532 3533
3533static void free_fs_root(struct btrfs_root *root) 3534static void free_fs_root(struct btrfs_root *root)
3534{ 3535{
3535 iput(root->cache_inode); 3536 iput(root->ino_cache_inode);
3536 WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree)); 3537 WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree));
3537 btrfs_free_block_rsv(root, root->orphan_block_rsv); 3538 btrfs_free_block_rsv(root, root->orphan_block_rsv);
3538 root->orphan_block_rsv = NULL; 3539 root->orphan_block_rsv = NULL;
@@ -3623,7 +3624,7 @@ int btrfs_commit_super(struct btrfs_root *root)
3623 return btrfs_commit_transaction(trans, root); 3624 return btrfs_commit_transaction(trans, root);
3624} 3625}
3625 3626
3626int close_ctree(struct btrfs_root *root) 3627void close_ctree(struct btrfs_root *root)
3627{ 3628{
3628 struct btrfs_fs_info *fs_info = root->fs_info; 3629 struct btrfs_fs_info *fs_info = root->fs_info;
3629 int ret; 3630 int ret;
@@ -3689,6 +3690,7 @@ int close_ctree(struct btrfs_root *root)
3689 invalidate_inode_pages2(fs_info->btree_inode->i_mapping); 3690 invalidate_inode_pages2(fs_info->btree_inode->i_mapping);
3690 btrfs_stop_all_workers(fs_info); 3691 btrfs_stop_all_workers(fs_info);
3691 3692
3693 fs_info->open = 0;
3692 free_root_pointers(fs_info, 1); 3694 free_root_pointers(fs_info, 1);
3693 3695
3694 iput(fs_info->btree_inode); 3696 iput(fs_info->btree_inode);
@@ -3711,8 +3713,6 @@ int close_ctree(struct btrfs_root *root)
3711 3713
3712 btrfs_free_block_rsv(root, root->orphan_block_rsv); 3714 btrfs_free_block_rsv(root, root->orphan_block_rsv);
3713 root->orphan_block_rsv = NULL; 3715 root->orphan_block_rsv = NULL;
3714
3715 return 0;
3716} 3716}
3717 3717
3718int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid, 3718int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
@@ -3814,10 +3814,73 @@ int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid)
3814static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, 3814static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
3815 int read_only) 3815 int read_only)
3816{ 3816{
3817 struct btrfs_super_block *sb = fs_info->super_copy;
3818 int ret = 0;
3819
3820 if (sb->root_level > BTRFS_MAX_LEVEL) {
3821 printk(KERN_ERR "BTRFS: tree_root level too big: %d > %d\n",
3822 sb->root_level, BTRFS_MAX_LEVEL);
3823 ret = -EINVAL;
3824 }
3825 if (sb->chunk_root_level > BTRFS_MAX_LEVEL) {
3826 printk(KERN_ERR "BTRFS: chunk_root level too big: %d > %d\n",
3827 sb->chunk_root_level, BTRFS_MAX_LEVEL);
3828 ret = -EINVAL;
3829 }
3830 if (sb->log_root_level > BTRFS_MAX_LEVEL) {
3831 printk(KERN_ERR "BTRFS: log_root level too big: %d > %d\n",
3832 sb->log_root_level, BTRFS_MAX_LEVEL);
3833 ret = -EINVAL;
3834 }
3835
3817 /* 3836 /*
3818 * Placeholder for checks 3837 * The common minimum, we don't know if we can trust the nodesize/sectorsize
3838 * items yet, they'll be verified later. Issue just a warning.
3819 */ 3839 */
3820 return 0; 3840 if (!IS_ALIGNED(sb->root, 4096))
3841 printk(KERN_WARNING "BTRFS: tree_root block unaligned: %llu\n",
3842 sb->root);
3843 if (!IS_ALIGNED(sb->chunk_root, 4096))
3844 printk(KERN_WARNING "BTRFS: tree_root block unaligned: %llu\n",
3845 sb->chunk_root);
3846 if (!IS_ALIGNED(sb->log_root, 4096))
3847 printk(KERN_WARNING "BTRFS: tree_root block unaligned: %llu\n",
3848 sb->log_root);
3849
3850 if (memcmp(fs_info->fsid, sb->dev_item.fsid, BTRFS_UUID_SIZE) != 0) {
3851 printk(KERN_ERR "BTRFS: dev_item UUID does not match fsid: %pU != %pU\n",
3852 fs_info->fsid, sb->dev_item.fsid);
3853 ret = -EINVAL;
3854 }
3855
3856 /*
3857 * Hint to catch really bogus numbers, bitflips or so, more exact checks are
3858 * done later
3859 */
3860 if (sb->num_devices > (1UL << 31))
3861 printk(KERN_WARNING "BTRFS: suspicious number of devices: %llu\n",
3862 sb->num_devices);
3863
3864 if (sb->bytenr != BTRFS_SUPER_INFO_OFFSET) {
3865 printk(KERN_ERR "BTRFS: super offset mismatch %llu != %u\n",
3866 sb->bytenr, BTRFS_SUPER_INFO_OFFSET);
3867 ret = -EINVAL;
3868 }
3869
3870 /*
3871 * The generation is a global counter, we'll trust it more than the others
3872 * but it's still possible that it's the one that's wrong.
3873 */
3874 if (sb->generation < sb->chunk_root_generation)
3875 printk(KERN_WARNING
3876 "BTRFS: suspicious: generation < chunk_root_generation: %llu < %llu\n",
3877 sb->generation, sb->chunk_root_generation);
3878 if (sb->generation < sb->cache_generation && sb->cache_generation != (u64)-1)
3879 printk(KERN_WARNING
3880 "BTRFS: suspicious: generation < cache_generation: %llu < %llu\n",
3881 sb->generation, sb->cache_generation);
3882
3883 return ret;
3821} 3884}
3822 3885
3823static void btrfs_error_commit_super(struct btrfs_root *root) 3886static void btrfs_error_commit_super(struct btrfs_root *root)
@@ -4009,9 +4072,8 @@ static int btrfs_destroy_marked_extents(struct btrfs_root *root,
4009 4072
4010 clear_extent_bits(dirty_pages, start, end, mark, GFP_NOFS); 4073 clear_extent_bits(dirty_pages, start, end, mark, GFP_NOFS);
4011 while (start <= end) { 4074 while (start <= end) {
4012 eb = btrfs_find_tree_block(root, start, 4075 eb = btrfs_find_tree_block(root, start);
4013 root->leafsize); 4076 start += root->nodesize;
4014 start += root->leafsize;
4015 if (!eb) 4077 if (!eb)
4016 continue; 4078 continue;
4017 wait_on_extent_buffer_writeback(eb); 4079 wait_on_extent_buffer_writeback(eb);