aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2016-06-22 18:54:23 -0400
committerDavid Sterba <dsterba@suse.com>2016-12-06 10:06:59 -0500
commit0b246afa62b0cf5b09d078121f543135f28492ad (patch)
tree200ad296d09f1b2f5329658c8de81bc625007ace /fs/btrfs/disk-io.c
parent6202df6921494f29308307e0ae6f567c2ab2ba19 (diff)
btrfs: root->fs_info cleanup, add fs_info convenience variables
In routines where someptr->fs_info is referenced multiple times, we introduce a convenience variable. This makes the code considerably more readable. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c268
1 files changed, 143 insertions, 125 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 5abf3afa6ea5..02ba794d171e 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -224,6 +224,7 @@ static struct extent_map *btree_get_extent(struct inode *inode,
224 struct page *page, size_t pg_offset, u64 start, u64 len, 224 struct page *page, size_t pg_offset, u64 start, u64 len,
225 int create) 225 int create)
226{ 226{
227 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
227 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; 228 struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree;
228 struct extent_map *em; 229 struct extent_map *em;
229 int ret; 230 int ret;
@@ -231,8 +232,7 @@ static struct extent_map *btree_get_extent(struct inode *inode,
231 read_lock(&em_tree->lock); 232 read_lock(&em_tree->lock);
232 em = lookup_extent_mapping(em_tree, start, len); 233 em = lookup_extent_mapping(em_tree, start, len);
233 if (em) { 234 if (em) {
234 em->bdev = 235 em->bdev = fs_info->fs_devices->latest_bdev;
235 BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev;
236 read_unlock(&em_tree->lock); 236 read_unlock(&em_tree->lock);
237 goto out; 237 goto out;
238 } 238 }
@@ -247,7 +247,7 @@ static struct extent_map *btree_get_extent(struct inode *inode,
247 em->len = (u64)-1; 247 em->len = (u64)-1;
248 em->block_len = (u64)-1; 248 em->block_len = (u64)-1;
249 em->block_start = 0; 249 em->block_start = 0;
250 em->bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; 250 em->bdev = fs_info->fs_devices->latest_bdev;
251 251
252 write_lock(&em_tree->lock); 252 write_lock(&em_tree->lock);
253 ret = add_extent_mapping(em_tree, em, 0); 253 ret = add_extent_mapping(em_tree, em, 0);
@@ -444,6 +444,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root,
444 struct extent_buffer *eb, 444 struct extent_buffer *eb,
445 u64 parent_transid) 445 u64 parent_transid)
446{ 446{
447 struct btrfs_fs_info *fs_info = root->fs_info;
447 struct extent_io_tree *io_tree; 448 struct extent_io_tree *io_tree;
448 int failed = 0; 449 int failed = 0;
449 int ret; 450 int ret;
@@ -452,7 +453,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root,
452 int failed_mirror = 0; 453 int failed_mirror = 0;
453 454
454 clear_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags); 455 clear_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags);
455 io_tree = &BTRFS_I(root->fs_info->btree_inode)->io_tree; 456 io_tree = &BTRFS_I(fs_info->btree_inode)->io_tree;
456 while (1) { 457 while (1) {
457 ret = read_extent_buffer_pages(io_tree, eb, WAIT_COMPLETE, 458 ret = read_extent_buffer_pages(io_tree, eb, WAIT_COMPLETE,
458 btree_get_extent, mirror_num); 459 btree_get_extent, mirror_num);
@@ -472,7 +473,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root,
472 if (test_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags)) 473 if (test_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags))
473 break; 474 break;
474 475
475 num_copies = btrfs_num_copies(root->fs_info, 476 num_copies = btrfs_num_copies(fs_info,
476 eb->start, eb->len); 477 eb->start, eb->len);
477 if (num_copies == 1) 478 if (num_copies == 1)
478 break; 479 break;
@@ -545,15 +546,16 @@ static int check_tree_block_fsid(struct btrfs_fs_info *fs_info,
545 return ret; 546 return ret;
546} 547}
547 548
548#define CORRUPT(reason, eb, root, slot) \ 549#define CORRUPT(reason, eb, root, slot) \
549 btrfs_crit(root->fs_info, "corrupt %s, %s: block=%llu," \ 550 btrfs_crit(root->fs_info, \
550 " root=%llu, slot=%d", \ 551 "corrupt %s, %s: block=%llu, root=%llu, slot=%d", \
551 btrfs_header_level(eb) == 0 ? "leaf" : "node",\ 552 btrfs_header_level(eb) == 0 ? "leaf" : "node", \
552 reason, btrfs_header_bytenr(eb), root->objectid, slot) 553 reason, btrfs_header_bytenr(eb), root->objectid, slot)
553 554
554static noinline int check_leaf(struct btrfs_root *root, 555static noinline int check_leaf(struct btrfs_root *root,
555 struct extent_buffer *leaf) 556 struct extent_buffer *leaf)
556{ 557{
558 struct btrfs_fs_info *fs_info = root->fs_info;
557 struct btrfs_key key; 559 struct btrfs_key key;
558 struct btrfs_key leaf_key; 560 struct btrfs_key leaf_key;
559 u32 nritems = btrfs_header_nritems(leaf); 561 u32 nritems = btrfs_header_nritems(leaf);
@@ -566,7 +568,7 @@ static noinline int check_leaf(struct btrfs_root *root,
566 key.type = BTRFS_ROOT_ITEM_KEY; 568 key.type = BTRFS_ROOT_ITEM_KEY;
567 key.offset = (u64)-1; 569 key.offset = (u64)-1;
568 570
569 check_root = btrfs_get_fs_root(root->fs_info, &key, false); 571 check_root = btrfs_get_fs_root(fs_info, &key, false);
570 /* 572 /*
571 * The only reason we also check NULL here is that during 573 * The only reason we also check NULL here is that during
572 * open_ctree() some roots has not yet been set up. 574 * open_ctree() some roots has not yet been set up.
@@ -585,7 +587,7 @@ static noinline int check_leaf(struct btrfs_root *root,
585 587
586 /* Check the 0 item */ 588 /* Check the 0 item */
587 if (btrfs_item_offset_nr(leaf, 0) + btrfs_item_size_nr(leaf, 0) != 589 if (btrfs_item_offset_nr(leaf, 0) + btrfs_item_size_nr(leaf, 0) !=
588 BTRFS_LEAF_DATA_SIZE(root->fs_info)) { 590 BTRFS_LEAF_DATA_SIZE(fs_info)) {
589 CORRUPT("invalid item offset size pair", leaf, root, 0); 591 CORRUPT("invalid item offset size pair", leaf, root, 0);
590 return -EIO; 592 return -EIO;
591 } 593 }
@@ -624,7 +626,7 @@ static noinline int check_leaf(struct btrfs_root *root,
624 * all point outside of the leaf. 626 * all point outside of the leaf.
625 */ 627 */
626 if (btrfs_item_end_nr(leaf, slot) > 628 if (btrfs_item_end_nr(leaf, slot) >
627 BTRFS_LEAF_DATA_SIZE(root->fs_info)) { 629 BTRFS_LEAF_DATA_SIZE(fs_info)) {
628 CORRUPT("slot end outside of leaf", leaf, root, slot); 630 CORRUPT("slot end outside of leaf", leaf, root, slot);
629 return -EIO; 631 return -EIO;
630 } 632 }
@@ -1004,6 +1006,7 @@ static int btree_submit_bio_hook(struct inode *inode, struct bio *bio,
1004 int mirror_num, unsigned long bio_flags, 1006 int mirror_num, unsigned long bio_flags,
1005 u64 bio_offset) 1007 u64 bio_offset)
1006{ 1008{
1009 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
1007 int async = check_async_write(inode, bio_flags); 1010 int async = check_async_write(inode, bio_flags);
1008 int ret; 1011 int ret;
1009 1012
@@ -1012,8 +1015,8 @@ static int btree_submit_bio_hook(struct inode *inode, struct bio *bio,
1012 * called for a read, do the setup so that checksum validation 1015 * called for a read, do the setup so that checksum validation
1013 * can happen in the async kernel threads 1016 * can happen in the async kernel threads
1014 */ 1017 */
1015 ret = btrfs_bio_wq_end_io(BTRFS_I(inode)->root->fs_info, 1018 ret = btrfs_bio_wq_end_io(fs_info, bio,
1016 bio, BTRFS_WQ_ENDIO_METADATA); 1019 BTRFS_WQ_ENDIO_METADATA);
1017 if (ret) 1020 if (ret)
1018 goto out_w_error; 1021 goto out_w_error;
1019 ret = btrfs_map_bio(BTRFS_I(inode)->root, bio, mirror_num, 0); 1022 ret = btrfs_map_bio(BTRFS_I(inode)->root, bio, mirror_num, 0);
@@ -1027,8 +1030,7 @@ static int btree_submit_bio_hook(struct inode *inode, struct bio *bio,
1027 * kthread helpers are used to submit writes so that 1030 * kthread helpers are used to submit writes so that
1028 * checksumming can happen in parallel across all CPUs 1031 * checksumming can happen in parallel across all CPUs
1029 */ 1032 */
1030 ret = btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info, 1033 ret = btrfs_wq_submit_bio(fs_info, inode, bio, mirror_num, 0,
1031 inode, bio, mirror_num, 0,
1032 bio_offset, 1034 bio_offset,
1033 __btree_submit_bio_start, 1035 __btree_submit_bio_start,
1034 __btree_submit_bio_done); 1036 __btree_submit_bio_done);
@@ -1194,9 +1196,11 @@ int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr,
1194struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, 1196struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
1195 u64 bytenr) 1197 u64 bytenr)
1196{ 1198{
1197 if (btrfs_is_testing(root->fs_info)) 1199 struct btrfs_fs_info *fs_info = root->fs_info;
1198 return alloc_test_extent_buffer(root->fs_info, bytenr); 1200
1199 return alloc_extent_buffer(root->fs_info, bytenr); 1201 if (btrfs_is_testing(fs_info))
1202 return alloc_test_extent_buffer(fs_info, bytenr);
1203 return alloc_extent_buffer(fs_info, bytenr);
1200} 1204}
1201 1205
1202 1206
@@ -1493,7 +1497,7 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1493 btrfs_set_header_owner(leaf, BTRFS_TREE_LOG_OBJECTID); 1497 btrfs_set_header_owner(leaf, BTRFS_TREE_LOG_OBJECTID);
1494 root->node = leaf; 1498 root->node = leaf;
1495 1499
1496 write_extent_buffer_fsid(root->node, root->fs_info->fsid); 1500 write_extent_buffer_fsid(root->node, fs_info->fsid);
1497 btrfs_mark_buffer_dirty(root->node); 1501 btrfs_mark_buffer_dirty(root->node);
1498 btrfs_tree_unlock(root->node); 1502 btrfs_tree_unlock(root->node);
1499 return root; 1503 return root;
@@ -1515,10 +1519,11 @@ int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
1515int btrfs_add_log_tree(struct btrfs_trans_handle *trans, 1519int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
1516 struct btrfs_root *root) 1520 struct btrfs_root *root)
1517{ 1521{
1522 struct btrfs_fs_info *fs_info = root->fs_info;
1518 struct btrfs_root *log_root; 1523 struct btrfs_root *log_root;
1519 struct btrfs_inode_item *inode_item; 1524 struct btrfs_inode_item *inode_item;
1520 1525
1521 log_root = alloc_log_tree(trans, root->fs_info); 1526 log_root = alloc_log_tree(trans, fs_info);
1522 if (IS_ERR(log_root)) 1527 if (IS_ERR(log_root))
1523 return PTR_ERR(log_root); 1528 return PTR_ERR(log_root);
1524 1529
@@ -1530,7 +1535,7 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
1530 btrfs_set_stack_inode_size(inode_item, 3); 1535 btrfs_set_stack_inode_size(inode_item, 3);
1531 btrfs_set_stack_inode_nlink(inode_item, 1); 1536 btrfs_set_stack_inode_nlink(inode_item, 1);
1532 btrfs_set_stack_inode_nbytes(inode_item, 1537 btrfs_set_stack_inode_nbytes(inode_item,
1533 root->fs_info->nodesize); 1538 fs_info->nodesize);
1534 btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755); 1539 btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755);
1535 1540
1536 btrfs_set_root_node(&log_root->root_item, log_root->node); 1541 btrfs_set_root_node(&log_root->root_item, log_root->node);
@@ -1828,6 +1833,7 @@ static void end_workqueue_fn(struct btrfs_work *work)
1828static int cleaner_kthread(void *arg) 1833static int cleaner_kthread(void *arg)
1829{ 1834{
1830 struct btrfs_root *root = arg; 1835 struct btrfs_root *root = arg;
1836 struct btrfs_fs_info *fs_info = root->fs_info;
1831 int again; 1837 int again;
1832 struct btrfs_trans_handle *trans; 1838 struct btrfs_trans_handle *trans;
1833 1839
@@ -1842,10 +1848,10 @@ static int cleaner_kthread(void *arg)
1842 * Do not do anything if we might cause open_ctree() to block 1848 * Do not do anything if we might cause open_ctree() to block
1843 * before we have finished mounting the filesystem. 1849 * before we have finished mounting the filesystem.
1844 */ 1850 */
1845 if (!test_bit(BTRFS_FS_OPEN, &root->fs_info->flags)) 1851 if (!test_bit(BTRFS_FS_OPEN, &fs_info->flags))
1846 goto sleep; 1852 goto sleep;
1847 1853
1848 if (!mutex_trylock(&root->fs_info->cleaner_mutex)) 1854 if (!mutex_trylock(&fs_info->cleaner_mutex))
1849 goto sleep; 1855 goto sleep;
1850 1856
1851 /* 1857 /*
@@ -1853,22 +1859,22 @@ static int cleaner_kthread(void *arg)
1853 * during the above check and trylock. 1859 * during the above check and trylock.
1854 */ 1860 */
1855 if (btrfs_need_cleaner_sleep(root)) { 1861 if (btrfs_need_cleaner_sleep(root)) {
1856 mutex_unlock(&root->fs_info->cleaner_mutex); 1862 mutex_unlock(&fs_info->cleaner_mutex);
1857 goto sleep; 1863 goto sleep;
1858 } 1864 }
1859 1865
1860 mutex_lock(&root->fs_info->cleaner_delayed_iput_mutex); 1866 mutex_lock(&fs_info->cleaner_delayed_iput_mutex);
1861 btrfs_run_delayed_iputs(root); 1867 btrfs_run_delayed_iputs(root);
1862 mutex_unlock(&root->fs_info->cleaner_delayed_iput_mutex); 1868 mutex_unlock(&fs_info->cleaner_delayed_iput_mutex);
1863 1869
1864 again = btrfs_clean_one_deleted_snapshot(root); 1870 again = btrfs_clean_one_deleted_snapshot(root);
1865 mutex_unlock(&root->fs_info->cleaner_mutex); 1871 mutex_unlock(&fs_info->cleaner_mutex);
1866 1872
1867 /* 1873 /*
1868 * The defragger has dealt with the R/O remount and umount, 1874 * The defragger has dealt with the R/O remount and umount,
1869 * needn't do anything special here. 1875 * needn't do anything special here.
1870 */ 1876 */
1871 btrfs_run_defrag_inodes(root->fs_info); 1877 btrfs_run_defrag_inodes(fs_info);
1872 1878
1873 /* 1879 /*
1874 * Acquires fs_info->delete_unused_bgs_mutex to avoid racing 1880 * Acquires fs_info->delete_unused_bgs_mutex to avoid racing
@@ -1878,7 +1884,7 @@ static int cleaner_kthread(void *arg)
1878 * can't hold, nor need to, fs_info->cleaner_mutex when deleting 1884 * can't hold, nor need to, fs_info->cleaner_mutex when deleting
1879 * unused block groups. 1885 * unused block groups.
1880 */ 1886 */
1881 btrfs_delete_unused_bgs(root->fs_info); 1887 btrfs_delete_unused_bgs(fs_info);
1882sleep: 1888sleep:
1883 if (!again) { 1889 if (!again) {
1884 set_current_state(TASK_INTERRUPTIBLE); 1890 set_current_state(TASK_INTERRUPTIBLE);
@@ -1902,7 +1908,7 @@ sleep:
1902 trans = btrfs_attach_transaction(root); 1908 trans = btrfs_attach_transaction(root);
1903 if (IS_ERR(trans)) { 1909 if (IS_ERR(trans)) {
1904 if (PTR_ERR(trans) != -ENOENT) 1910 if (PTR_ERR(trans) != -ENOENT)
1905 btrfs_err(root->fs_info, 1911 btrfs_err(fs_info,
1906 "cleaner transaction attach returned %ld", 1912 "cleaner transaction attach returned %ld",
1907 PTR_ERR(trans)); 1913 PTR_ERR(trans));
1908 } else { 1914 } else {
@@ -1910,7 +1916,7 @@ sleep:
1910 1916
1911 ret = btrfs_commit_transaction(trans, root); 1917 ret = btrfs_commit_transaction(trans, root);
1912 if (ret) 1918 if (ret)
1913 btrfs_err(root->fs_info, 1919 btrfs_err(fs_info,
1914 "cleaner open transaction commit returned %d", 1920 "cleaner open transaction commit returned %d",
1915 ret); 1921 ret);
1916 } 1922 }
@@ -1921,6 +1927,7 @@ sleep:
1921static int transaction_kthread(void *arg) 1927static int transaction_kthread(void *arg)
1922{ 1928{
1923 struct btrfs_root *root = arg; 1929 struct btrfs_root *root = arg;
1930 struct btrfs_fs_info *fs_info = root->fs_info;
1924 struct btrfs_trans_handle *trans; 1931 struct btrfs_trans_handle *trans;
1925 struct btrfs_transaction *cur; 1932 struct btrfs_transaction *cur;
1926 u64 transid; 1933 u64 transid;
@@ -1930,26 +1937,26 @@ static int transaction_kthread(void *arg)
1930 1937
1931 do { 1938 do {
1932 cannot_commit = false; 1939 cannot_commit = false;
1933 delay = HZ * root->fs_info->commit_interval; 1940 delay = HZ * fs_info->commit_interval;
1934 mutex_lock(&root->fs_info->transaction_kthread_mutex); 1941 mutex_lock(&fs_info->transaction_kthread_mutex);
1935 1942
1936 spin_lock(&root->fs_info->trans_lock); 1943 spin_lock(&fs_info->trans_lock);
1937 cur = root->fs_info->running_transaction; 1944 cur = fs_info->running_transaction;
1938 if (!cur) { 1945 if (!cur) {
1939 spin_unlock(&root->fs_info->trans_lock); 1946 spin_unlock(&fs_info->trans_lock);
1940 goto sleep; 1947 goto sleep;
1941 } 1948 }
1942 1949
1943 now = get_seconds(); 1950 now = get_seconds();
1944 if (cur->state < TRANS_STATE_BLOCKED && 1951 if (cur->state < TRANS_STATE_BLOCKED &&
1945 (now < cur->start_time || 1952 (now < cur->start_time ||
1946 now - cur->start_time < root->fs_info->commit_interval)) { 1953 now - cur->start_time < fs_info->commit_interval)) {
1947 spin_unlock(&root->fs_info->trans_lock); 1954 spin_unlock(&fs_info->trans_lock);
1948 delay = HZ * 5; 1955 delay = HZ * 5;
1949 goto sleep; 1956 goto sleep;
1950 } 1957 }
1951 transid = cur->transid; 1958 transid = cur->transid;
1952 spin_unlock(&root->fs_info->trans_lock); 1959 spin_unlock(&fs_info->trans_lock);
1953 1960
1954 /* If the file system is aborted, this will always fail. */ 1961 /* If the file system is aborted, this will always fail. */
1955 trans = btrfs_attach_transaction(root); 1962 trans = btrfs_attach_transaction(root);
@@ -1964,15 +1971,15 @@ static int transaction_kthread(void *arg)
1964 btrfs_end_transaction(trans, root); 1971 btrfs_end_transaction(trans, root);
1965 } 1972 }
1966sleep: 1973sleep:
1967 wake_up_process(root->fs_info->cleaner_kthread); 1974 wake_up_process(fs_info->cleaner_kthread);
1968 mutex_unlock(&root->fs_info->transaction_kthread_mutex); 1975 mutex_unlock(&fs_info->transaction_kthread_mutex);
1969 1976
1970 if (unlikely(test_bit(BTRFS_FS_STATE_ERROR, 1977 if (unlikely(test_bit(BTRFS_FS_STATE_ERROR,
1971 &root->fs_info->fs_state))) 1978 &fs_info->fs_state)))
1972 btrfs_cleanup_transaction(root); 1979 btrfs_cleanup_transaction(root);
1973 set_current_state(TASK_INTERRUPTIBLE); 1980 set_current_state(TASK_INTERRUPTIBLE);
1974 if (!kthread_should_stop() && 1981 if (!kthread_should_stop() &&
1975 (!btrfs_transaction_blocked(root->fs_info) || 1982 (!btrfs_transaction_blocked(fs_info) ||
1976 cannot_commit)) 1983 cannot_commit))
1977 schedule_timeout(delay); 1984 schedule_timeout(delay);
1978 __set_current_state(TASK_RUNNING); 1985 __set_current_state(TASK_RUNNING);
@@ -2464,8 +2471,8 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
2464 /* returns with log_tree_root freed on success */ 2471 /* returns with log_tree_root freed on success */
2465 ret = btrfs_recover_log_trees(log_tree_root); 2472 ret = btrfs_recover_log_trees(log_tree_root);
2466 if (ret) { 2473 if (ret) {
2467 btrfs_handle_fs_error(tree_root->fs_info, ret, 2474 btrfs_handle_fs_error(fs_info, ret,
2468 "Failed to recover log tree"); 2475 "Failed to recover log tree");
2469 free_extent_buffer(log_tree_root->node); 2476 free_extent_buffer(log_tree_root->node);
2470 kfree(log_tree_root); 2477 kfree(log_tree_root);
2471 return ret; 2478 return ret;
@@ -2830,7 +2837,7 @@ int open_ctree(struct super_block *sb,
2830 2837
2831 features = btrfs_super_incompat_flags(disk_super); 2838 features = btrfs_super_incompat_flags(disk_super);
2832 features |= BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF; 2839 features |= BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF;
2833 if (tree_root->fs_info->compress_type == BTRFS_COMPRESS_LZO) 2840 if (fs_info->compress_type == BTRFS_COMPRESS_LZO)
2834 features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO; 2841 features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
2835 2842
2836 if (features & BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA) 2843 if (features & BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
@@ -3059,8 +3066,8 @@ retry_root_backup:
3059 if (IS_ERR(fs_info->transaction_kthread)) 3066 if (IS_ERR(fs_info->transaction_kthread))
3060 goto fail_cleaner; 3067 goto fail_cleaner;
3061 3068
3062 if (!btrfs_test_opt(tree_root->fs_info, SSD) && 3069 if (!btrfs_test_opt(fs_info, SSD) &&
3063 !btrfs_test_opt(tree_root->fs_info, NOSSD) && 3070 !btrfs_test_opt(fs_info, NOSSD) &&
3064 !fs_info->fs_devices->rotating) { 3071 !fs_info->fs_devices->rotating) {
3065 btrfs_info(fs_info, "detected SSD devices, enabling SSD mode"); 3072 btrfs_info(fs_info, "detected SSD devices, enabling SSD mode");
3066 btrfs_set_opt(fs_info->mount_opt, SSD); 3073 btrfs_set_opt(fs_info->mount_opt, SSD);
@@ -3073,9 +3080,9 @@ retry_root_backup:
3073 btrfs_apply_pending_changes(fs_info); 3080 btrfs_apply_pending_changes(fs_info);
3074 3081
3075#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY 3082#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
3076 if (btrfs_test_opt(tree_root->fs_info, CHECK_INTEGRITY)) { 3083 if (btrfs_test_opt(fs_info, CHECK_INTEGRITY)) {
3077 ret = btrfsic_mount(tree_root, fs_devices, 3084 ret = btrfsic_mount(tree_root, fs_devices,
3078 btrfs_test_opt(tree_root->fs_info, 3085 btrfs_test_opt(fs_info,
3079 CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ? 3086 CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ?
3080 1 : 0, 3087 1 : 0,
3081 fs_info->check_integrity_print_mask); 3088 fs_info->check_integrity_print_mask);
@@ -3091,7 +3098,7 @@ retry_root_backup:
3091 3098
3092 /* do not make disk changes in broken FS or nologreplay is given */ 3099 /* do not make disk changes in broken FS or nologreplay is given */
3093 if (btrfs_super_log_root(disk_super) != 0 && 3100 if (btrfs_super_log_root(disk_super) != 0 &&
3094 !btrfs_test_opt(tree_root->fs_info, NOLOGREPLAY)) { 3101 !btrfs_test_opt(fs_info, NOLOGREPLAY)) {
3095 ret = btrfs_replay_log(fs_info, fs_devices); 3102 ret = btrfs_replay_log(fs_info, fs_devices);
3096 if (ret) { 3103 if (ret) {
3097 err = ret; 3104 err = ret;
@@ -3152,7 +3159,7 @@ retry_root_backup:
3152 } 3159 }
3153 } 3160 }
3154 3161
3155 if (btrfs_test_opt(tree_root->fs_info, FREE_SPACE_TREE) && 3162 if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) &&
3156 !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) { 3163 !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
3157 btrfs_info(fs_info, "creating free space tree"); 3164 btrfs_info(fs_info, "creating free space tree");
3158 ret = btrfs_create_free_space_tree(fs_info); 3165 ret = btrfs_create_free_space_tree(fs_info);
@@ -3198,7 +3205,7 @@ retry_root_backup:
3198 close_ctree(fs_info); 3205 close_ctree(fs_info);
3199 return ret; 3206 return ret;
3200 } 3207 }
3201 } else if (btrfs_test_opt(tree_root->fs_info, RESCAN_UUID_TREE) || 3208 } else if (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) ||
3202 fs_info->generation != 3209 fs_info->generation !=
3203 btrfs_super_uuid_tree_generation(disk_super)) { 3210 btrfs_super_uuid_tree_generation(disk_super)) {
3204 btrfs_info(fs_info, "checking UUID tree"); 3211 btrfs_info(fs_info, "checking UUID tree");
@@ -3274,7 +3281,7 @@ fail:
3274 return err; 3281 return err;
3275 3282
3276recovery_tree_root: 3283recovery_tree_root:
3277 if (!btrfs_test_opt(tree_root->fs_info, USEBACKUPROOT)) 3284 if (!btrfs_test_opt(fs_info, USEBACKUPROOT))
3278 goto fail_tree_roots; 3285 goto fail_tree_roots;
3279 3286
3280 free_root_pointers(fs_info, 0); 3287 free_root_pointers(fs_info, 0);
@@ -3680,6 +3687,7 @@ int btrfs_calc_num_tolerated_disk_barrier_failures(
3680 3687
3681static int write_all_supers(struct btrfs_root *root, int max_mirrors) 3688static int write_all_supers(struct btrfs_root *root, int max_mirrors)
3682{ 3689{
3690 struct btrfs_fs_info *fs_info = root->fs_info;
3683 struct list_head *head; 3691 struct list_head *head;
3684 struct btrfs_device *dev; 3692 struct btrfs_device *dev;
3685 struct btrfs_super_block *sb; 3693 struct btrfs_super_block *sb;
@@ -3690,23 +3698,23 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors)
3690 int total_errors = 0; 3698 int total_errors = 0;
3691 u64 flags; 3699 u64 flags;
3692 3700
3693 do_barriers = !btrfs_test_opt(root->fs_info, NOBARRIER); 3701 do_barriers = !btrfs_test_opt(fs_info, NOBARRIER);
3694 backup_super_roots(root->fs_info); 3702 backup_super_roots(fs_info);
3695 3703
3696 sb = root->fs_info->super_for_commit; 3704 sb = fs_info->super_for_commit;
3697 dev_item = &sb->dev_item; 3705 dev_item = &sb->dev_item;
3698 3706
3699 mutex_lock(&root->fs_info->fs_devices->device_list_mutex); 3707 mutex_lock(&fs_info->fs_devices->device_list_mutex);
3700 head = &root->fs_info->fs_devices->devices; 3708 head = &fs_info->fs_devices->devices;
3701 max_errors = btrfs_super_num_devices(root->fs_info->super_copy) - 1; 3709 max_errors = btrfs_super_num_devices(fs_info->super_copy) - 1;
3702 3710
3703 if (do_barriers) { 3711 if (do_barriers) {
3704 ret = barrier_all_devices(root->fs_info); 3712 ret = barrier_all_devices(fs_info);
3705 if (ret) { 3713 if (ret) {
3706 mutex_unlock( 3714 mutex_unlock(
3707 &root->fs_info->fs_devices->device_list_mutex); 3715 &fs_info->fs_devices->device_list_mutex);
3708 btrfs_handle_fs_error(root->fs_info, ret, 3716 btrfs_handle_fs_error(fs_info, ret,
3709 "errors while submitting device barriers."); 3717 "errors while submitting device barriers.");
3710 return ret; 3718 return ret;
3711 } 3719 }
3712 } 3720 }
@@ -3740,13 +3748,14 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors)
3740 total_errors++; 3748 total_errors++;
3741 } 3749 }
3742 if (total_errors > max_errors) { 3750 if (total_errors > max_errors) {
3743 btrfs_err(root->fs_info, "%d errors while writing supers", 3751 btrfs_err(fs_info, "%d errors while writing supers",
3744 total_errors); 3752 total_errors);
3745 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); 3753 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3746 3754
3747 /* FUA is masked off if unsupported and can't be the reason */ 3755 /* FUA is masked off if unsupported and can't be the reason */
3748 btrfs_handle_fs_error(root->fs_info, -EIO, 3756 btrfs_handle_fs_error(fs_info, -EIO,
3749 "%d errors while writing supers", total_errors); 3757 "%d errors while writing supers",
3758 total_errors);
3750 return -EIO; 3759 return -EIO;
3751 } 3760 }
3752 3761
@@ -3761,10 +3770,11 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors)
3761 if (ret) 3770 if (ret)
3762 total_errors++; 3771 total_errors++;
3763 } 3772 }
3764 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); 3773 mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3765 if (total_errors > max_errors) { 3774 if (total_errors > max_errors) {
3766 btrfs_handle_fs_error(root->fs_info, -EIO, 3775 btrfs_handle_fs_error(fs_info, -EIO,
3767 "%d errors while writing supers", total_errors); 3776 "%d errors while writing supers",
3777 total_errors);
3768 return -EIO; 3778 return -EIO;
3769 } 3779 }
3770 return 0; 3780 return 0;
@@ -3884,14 +3894,14 @@ int btrfs_commit_super(struct btrfs_fs_info *fs_info)
3884 struct btrfs_root *root = fs_info->tree_root; 3894 struct btrfs_root *root = fs_info->tree_root;
3885 struct btrfs_trans_handle *trans; 3895 struct btrfs_trans_handle *trans;
3886 3896
3887 mutex_lock(&root->fs_info->cleaner_mutex); 3897 mutex_lock(&fs_info->cleaner_mutex);
3888 btrfs_run_delayed_iputs(root); 3898 btrfs_run_delayed_iputs(root);
3889 mutex_unlock(&root->fs_info->cleaner_mutex); 3899 mutex_unlock(&fs_info->cleaner_mutex);
3890 wake_up_process(root->fs_info->cleaner_kthread); 3900 wake_up_process(fs_info->cleaner_kthread);
3891 3901
3892 /* wait until ongoing cleanup work done */ 3902 /* wait until ongoing cleanup work done */
3893 down_write(&root->fs_info->cleanup_work_sem); 3903 down_write(&fs_info->cleanup_work_sem);
3894 up_write(&root->fs_info->cleanup_work_sem); 3904 up_write(&fs_info->cleanup_work_sem);
3895 3905
3896 trans = btrfs_join_transaction(root); 3906 trans = btrfs_join_transaction(root);
3897 if (IS_ERR(trans)) 3907 if (IS_ERR(trans))
@@ -3936,7 +3946,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)
3936 * block groups queued for removal, the deletion will be 3946 * block groups queued for removal, the deletion will be
3937 * skipped when we quit the cleaner thread. 3947 * skipped when we quit the cleaner thread.
3938 */ 3948 */
3939 btrfs_delete_unused_bgs(root->fs_info); 3949 btrfs_delete_unused_bgs(fs_info);
3940 3950
3941 ret = btrfs_commit_super(fs_info); 3951 ret = btrfs_commit_super(fs_info);
3942 if (ret) 3952 if (ret)
@@ -3980,7 +3990,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)
3980 iput(fs_info->btree_inode); 3990 iput(fs_info->btree_inode);
3981 3991
3982#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY 3992#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
3983 if (btrfs_test_opt(root->fs_info, CHECK_INTEGRITY)) 3993 if (btrfs_test_opt(fs_info, CHECK_INTEGRITY))
3984 btrfsic_unmount(root, fs_info->fs_devices); 3994 btrfsic_unmount(root, fs_info->fs_devices);
3985#endif 3995#endif
3986 3996
@@ -3998,7 +4008,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)
3998 __btrfs_free_block_rsv(root->orphan_block_rsv); 4008 __btrfs_free_block_rsv(root->orphan_block_rsv);
3999 root->orphan_block_rsv = NULL; 4009 root->orphan_block_rsv = NULL;
4000 4010
4001 lock_chunks(root->fs_info); 4011 lock_chunks(fs_info);
4002 while (!list_empty(&fs_info->pinned_chunks)) { 4012 while (!list_empty(&fs_info->pinned_chunks)) {
4003 struct extent_map *em; 4013 struct extent_map *em;
4004 4014
@@ -4007,7 +4017,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)
4007 list_del_init(&em->list); 4017 list_del_init(&em->list);
4008 free_extent_map(em); 4018 free_extent_map(em);
4009 } 4019 }
4010 unlock_chunks(root->fs_info); 4020 unlock_chunks(fs_info);
4011} 4021}
4012 4022
4013int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid, 4023int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
@@ -4029,6 +4039,7 @@ int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
4029 4039
4030void btrfs_mark_buffer_dirty(struct extent_buffer *buf) 4040void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
4031{ 4041{
4042 struct btrfs_fs_info *fs_info;
4032 struct btrfs_root *root; 4043 struct btrfs_root *root;
4033 u64 transid = btrfs_header_generation(buf); 4044 u64 transid = btrfs_header_generation(buf);
4034 int was_dirty; 4045 int was_dirty;
@@ -4043,15 +4054,16 @@ void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
4043 return; 4054 return;
4044#endif 4055#endif
4045 root = BTRFS_I(buf->pages[0]->mapping->host)->root; 4056 root = BTRFS_I(buf->pages[0]->mapping->host)->root;
4057 fs_info = root->fs_info;
4046 btrfs_assert_tree_locked(buf); 4058 btrfs_assert_tree_locked(buf);
4047 if (transid != root->fs_info->generation) 4059 if (transid != fs_info->generation)
4048 WARN(1, KERN_CRIT "btrfs transid mismatch buffer %llu, found %llu running %llu\n", 4060 WARN(1, KERN_CRIT "btrfs transid mismatch buffer %llu, found %llu running %llu\n",
4049 buf->start, transid, root->fs_info->generation); 4061 buf->start, transid, fs_info->generation);
4050 was_dirty = set_extent_buffer_dirty(buf); 4062 was_dirty = set_extent_buffer_dirty(buf);
4051 if (!was_dirty) 4063 if (!was_dirty)
4052 __percpu_counter_add(&root->fs_info->dirty_metadata_bytes, 4064 __percpu_counter_add(&fs_info->dirty_metadata_bytes,
4053 buf->len, 4065 buf->len,
4054 root->fs_info->dirty_metadata_batch); 4066 fs_info->dirty_metadata_batch);
4055#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY 4067#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
4056 if (btrfs_header_level(buf) == 0 && check_leaf(root, buf)) { 4068 if (btrfs_header_level(buf) == 0 && check_leaf(root, buf)) {
4057 btrfs_print_leaf(root, buf); 4069 btrfs_print_leaf(root, buf);
@@ -4063,6 +4075,7 @@ void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
4063static void __btrfs_btree_balance_dirty(struct btrfs_root *root, 4075static void __btrfs_btree_balance_dirty(struct btrfs_root *root,
4064 int flush_delayed) 4076 int flush_delayed)
4065{ 4077{
4078 struct btrfs_fs_info *fs_info = root->fs_info;
4066 /* 4079 /*
4067 * looks as though older kernels can get into trouble with 4080 * looks as though older kernels can get into trouble with
4068 * this code, they end up stuck in balance_dirty_pages forever 4081 * this code, they end up stuck in balance_dirty_pages forever
@@ -4075,11 +4088,10 @@ static void __btrfs_btree_balance_dirty(struct btrfs_root *root,
4075 if (flush_delayed) 4088 if (flush_delayed)
4076 btrfs_balance_delayed_items(root); 4089 btrfs_balance_delayed_items(root);
4077 4090
4078 ret = percpu_counter_compare(&root->fs_info->dirty_metadata_bytes, 4091 ret = percpu_counter_compare(&fs_info->dirty_metadata_bytes,
4079 BTRFS_DIRTY_METADATA_THRESH); 4092 BTRFS_DIRTY_METADATA_THRESH);
4080 if (ret > 0) { 4093 if (ret > 0) {
4081 balance_dirty_pages_ratelimited( 4094 balance_dirty_pages_ratelimited(fs_info->btree_inode->i_mapping);
4082 root->fs_info->btree_inode->i_mapping);
4083 } 4095 }
4084} 4096}
4085 4097
@@ -4249,12 +4261,14 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
4249 4261
4250static void btrfs_error_commit_super(struct btrfs_root *root) 4262static void btrfs_error_commit_super(struct btrfs_root *root)
4251{ 4263{
4252 mutex_lock(&root->fs_info->cleaner_mutex); 4264 struct btrfs_fs_info *fs_info = root->fs_info;
4265
4266 mutex_lock(&fs_info->cleaner_mutex);
4253 btrfs_run_delayed_iputs(root); 4267 btrfs_run_delayed_iputs(root);
4254 mutex_unlock(&root->fs_info->cleaner_mutex); 4268 mutex_unlock(&fs_info->cleaner_mutex);
4255 4269
4256 down_write(&root->fs_info->cleanup_work_sem); 4270 down_write(&fs_info->cleanup_work_sem);
4257 up_write(&root->fs_info->cleanup_work_sem); 4271 up_write(&fs_info->cleanup_work_sem);
4258 4272
4259 /* cleanup FS via transaction */ 4273 /* cleanup FS via transaction */
4260 btrfs_cleanup_transaction(root); 4274 btrfs_cleanup_transaction(root);
@@ -4302,6 +4316,7 @@ static void btrfs_destroy_all_ordered_extents(struct btrfs_fs_info *fs_info)
4302static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, 4316static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
4303 struct btrfs_root *root) 4317 struct btrfs_root *root)
4304{ 4318{
4319 struct btrfs_fs_info *fs_info = root->fs_info;
4305 struct rb_node *node; 4320 struct rb_node *node;
4306 struct btrfs_delayed_ref_root *delayed_refs; 4321 struct btrfs_delayed_ref_root *delayed_refs;
4307 struct btrfs_delayed_ref_node *ref; 4322 struct btrfs_delayed_ref_node *ref;
@@ -4312,7 +4327,7 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
4312 spin_lock(&delayed_refs->lock); 4327 spin_lock(&delayed_refs->lock);
4313 if (atomic_read(&delayed_refs->num_entries) == 0) { 4328 if (atomic_read(&delayed_refs->num_entries) == 0) {
4314 spin_unlock(&delayed_refs->lock); 4329 spin_unlock(&delayed_refs->lock);
4315 btrfs_info(root->fs_info, "delayed_refs has NO entry"); 4330 btrfs_info(fs_info, "delayed_refs has NO entry");
4316 return ret; 4331 return ret;
4317 } 4332 }
4318 4333
@@ -4425,6 +4440,7 @@ static int btrfs_destroy_marked_extents(struct btrfs_root *root,
4425 struct extent_io_tree *dirty_pages, 4440 struct extent_io_tree *dirty_pages,
4426 int mark) 4441 int mark)
4427{ 4442{
4443 struct btrfs_fs_info *fs_info = root->fs_info;
4428 int ret; 4444 int ret;
4429 struct extent_buffer *eb; 4445 struct extent_buffer *eb;
4430 u64 start = 0; 4446 u64 start = 0;
@@ -4438,8 +4454,8 @@ static int btrfs_destroy_marked_extents(struct btrfs_root *root,
4438 4454
4439 clear_extent_bits(dirty_pages, start, end, mark); 4455 clear_extent_bits(dirty_pages, start, end, mark);
4440 while (start <= end) { 4456 while (start <= end) {
4441 eb = find_extent_buffer(root->fs_info, start); 4457 eb = find_extent_buffer(fs_info, start);
4442 start += root->fs_info->nodesize; 4458 start += fs_info->nodesize;
4443 if (!eb) 4459 if (!eb)
4444 continue; 4460 continue;
4445 wait_on_extent_buffer_writeback(eb); 4461 wait_on_extent_buffer_writeback(eb);
@@ -4457,6 +4473,7 @@ static int btrfs_destroy_marked_extents(struct btrfs_root *root,
4457static int btrfs_destroy_pinned_extent(struct btrfs_root *root, 4473static int btrfs_destroy_pinned_extent(struct btrfs_root *root,
4458 struct extent_io_tree *pinned_extents) 4474 struct extent_io_tree *pinned_extents)
4459{ 4475{
4476 struct btrfs_fs_info *fs_info = root->fs_info;
4460 struct extent_io_tree *unpin; 4477 struct extent_io_tree *unpin;
4461 u64 start; 4478 u64 start;
4462 u64 end; 4479 u64 end;
@@ -4477,10 +4494,10 @@ again:
4477 } 4494 }
4478 4495
4479 if (loop) { 4496 if (loop) {
4480 if (unpin == &root->fs_info->freed_extents[0]) 4497 if (unpin == &fs_info->freed_extents[0])
4481 unpin = &root->fs_info->freed_extents[1]; 4498 unpin = &fs_info->freed_extents[1];
4482 else 4499 else
4483 unpin = &root->fs_info->freed_extents[0]; 4500 unpin = &fs_info->freed_extents[0];
4484 loop = false; 4501 loop = false;
4485 goto again; 4502 goto again;
4486 } 4503 }
@@ -4505,6 +4522,7 @@ static void btrfs_cleanup_bg_io(struct btrfs_block_group_cache *cache)
4505void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *cur_trans, 4522void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *cur_trans,
4506 struct btrfs_root *root) 4523 struct btrfs_root *root)
4507{ 4524{
4525 struct btrfs_fs_info *fs_info = root->fs_info;
4508 struct btrfs_block_group_cache *cache; 4526 struct btrfs_block_group_cache *cache;
4509 4527
4510 spin_lock(&cur_trans->dirty_bgs_lock); 4528 spin_lock(&cur_trans->dirty_bgs_lock);
@@ -4513,8 +4531,7 @@ void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *cur_trans,
4513 struct btrfs_block_group_cache, 4531 struct btrfs_block_group_cache,
4514 dirty_list); 4532 dirty_list);
4515 if (!cache) { 4533 if (!cache) {
4516 btrfs_err(root->fs_info, 4534 btrfs_err(fs_info, "orphan block group dirty_bgs list");
4517 "orphan block group dirty_bgs list");
4518 spin_unlock(&cur_trans->dirty_bgs_lock); 4535 spin_unlock(&cur_trans->dirty_bgs_lock);
4519 return; 4536 return;
4520 } 4537 }
@@ -4542,8 +4559,7 @@ void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *cur_trans,
4542 struct btrfs_block_group_cache, 4559 struct btrfs_block_group_cache,
4543 io_list); 4560 io_list);
4544 if (!cache) { 4561 if (!cache) {
4545 btrfs_err(root->fs_info, 4562 btrfs_err(fs_info, "orphan block group on io_bgs list");
4546 "orphan block group on io_bgs list");
4547 return; 4563 return;
4548 } 4564 }
4549 4565
@@ -4558,6 +4574,7 @@ void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *cur_trans,
4558void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans, 4574void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
4559 struct btrfs_root *root) 4575 struct btrfs_root *root)
4560{ 4576{
4577 struct btrfs_fs_info *fs_info = root->fs_info;
4561 btrfs_cleanup_dirty_bgs(cur_trans, root); 4578 btrfs_cleanup_dirty_bgs(cur_trans, root);
4562 ASSERT(list_empty(&cur_trans->dirty_bgs)); 4579 ASSERT(list_empty(&cur_trans->dirty_bgs));
4563 ASSERT(list_empty(&cur_trans->io_bgs)); 4580 ASSERT(list_empty(&cur_trans->io_bgs));
@@ -4565,10 +4582,10 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
4565 btrfs_destroy_delayed_refs(cur_trans, root); 4582 btrfs_destroy_delayed_refs(cur_trans, root);
4566 4583
4567 cur_trans->state = TRANS_STATE_COMMIT_START; 4584 cur_trans->state = TRANS_STATE_COMMIT_START;
4568 wake_up(&root->fs_info->transaction_blocked_wait); 4585 wake_up(&fs_info->transaction_blocked_wait);
4569 4586
4570 cur_trans->state = TRANS_STATE_UNBLOCKED; 4587 cur_trans->state = TRANS_STATE_UNBLOCKED;
4571 wake_up(&root->fs_info->transaction_wait); 4588 wake_up(&fs_info->transaction_wait);
4572 4589
4573 btrfs_destroy_delayed_inodes(root); 4590 btrfs_destroy_delayed_inodes(root);
4574 btrfs_assert_delayed_root_empty(root); 4591 btrfs_assert_delayed_root_empty(root);
@@ -4576,7 +4593,7 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
4576 btrfs_destroy_marked_extents(root, &cur_trans->dirty_pages, 4593 btrfs_destroy_marked_extents(root, &cur_trans->dirty_pages,
4577 EXTENT_DIRTY); 4594 EXTENT_DIRTY);
4578 btrfs_destroy_pinned_extent(root, 4595 btrfs_destroy_pinned_extent(root,
4579 root->fs_info->pinned_extents); 4596 fs_info->pinned_extents);
4580 4597
4581 cur_trans->state =TRANS_STATE_COMPLETED; 4598 cur_trans->state =TRANS_STATE_COMPLETED;
4582 wake_up(&cur_trans->commit_wait); 4599 wake_up(&cur_trans->commit_wait);
@@ -4589,25 +4606,26 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
4589 4606
4590static int btrfs_cleanup_transaction(struct btrfs_root *root) 4607static int btrfs_cleanup_transaction(struct btrfs_root *root)
4591{ 4608{
4609 struct btrfs_fs_info *fs_info = root->fs_info;
4592 struct btrfs_transaction *t; 4610 struct btrfs_transaction *t;
4593 4611
4594 mutex_lock(&root->fs_info->transaction_kthread_mutex); 4612 mutex_lock(&fs_info->transaction_kthread_mutex);
4595 4613
4596 spin_lock(&root->fs_info->trans_lock); 4614 spin_lock(&fs_info->trans_lock);
4597 while (!list_empty(&root->fs_info->trans_list)) { 4615 while (!list_empty(&fs_info->trans_list)) {
4598 t = list_first_entry(&root->fs_info->trans_list, 4616 t = list_first_entry(&fs_info->trans_list,
4599 struct btrfs_transaction, list); 4617 struct btrfs_transaction, list);
4600 if (t->state >= TRANS_STATE_COMMIT_START) { 4618 if (t->state >= TRANS_STATE_COMMIT_START) {
4601 atomic_inc(&t->use_count); 4619 atomic_inc(&t->use_count);
4602 spin_unlock(&root->fs_info->trans_lock); 4620 spin_unlock(&fs_info->trans_lock);
4603 btrfs_wait_for_commit(root, t->transid); 4621 btrfs_wait_for_commit(root, t->transid);
4604 btrfs_put_transaction(t); 4622 btrfs_put_transaction(t);
4605 spin_lock(&root->fs_info->trans_lock); 4623 spin_lock(&fs_info->trans_lock);
4606 continue; 4624 continue;
4607 } 4625 }
4608 if (t == root->fs_info->running_transaction) { 4626 if (t == fs_info->running_transaction) {
4609 t->state = TRANS_STATE_COMMIT_DOING; 4627 t->state = TRANS_STATE_COMMIT_DOING;
4610 spin_unlock(&root->fs_info->trans_lock); 4628 spin_unlock(&fs_info->trans_lock);
4611 /* 4629 /*
4612 * We wait for 0 num_writers since we don't hold a trans 4630 * We wait for 0 num_writers since we don't hold a trans
4613 * handle open currently for this transaction. 4631 * handle open currently for this transaction.
@@ -4615,27 +4633,27 @@ static int btrfs_cleanup_transaction(struct btrfs_root *root)
4615 wait_event(t->writer_wait, 4633 wait_event(t->writer_wait,
4616 atomic_read(&t->num_writers) == 0); 4634 atomic_read(&t->num_writers) == 0);
4617 } else { 4635 } else {
4618 spin_unlock(&root->fs_info->trans_lock); 4636 spin_unlock(&fs_info->trans_lock);
4619 } 4637 }
4620 btrfs_cleanup_one_transaction(t, root); 4638 btrfs_cleanup_one_transaction(t, root);
4621 4639
4622 spin_lock(&root->fs_info->trans_lock); 4640 spin_lock(&fs_info->trans_lock);
4623 if (t == root->fs_info->running_transaction) 4641 if (t == fs_info->running_transaction)
4624 root->fs_info->running_transaction = NULL; 4642 fs_info->running_transaction = NULL;
4625 list_del_init(&t->list); 4643 list_del_init(&t->list);
4626 spin_unlock(&root->fs_info->trans_lock); 4644 spin_unlock(&fs_info->trans_lock);
4627 4645
4628 btrfs_put_transaction(t); 4646 btrfs_put_transaction(t);
4629 trace_btrfs_transaction_commit(root); 4647 trace_btrfs_transaction_commit(root);
4630 spin_lock(&root->fs_info->trans_lock); 4648 spin_lock(&fs_info->trans_lock);
4631 } 4649 }
4632 spin_unlock(&root->fs_info->trans_lock); 4650 spin_unlock(&fs_info->trans_lock);
4633 btrfs_destroy_all_ordered_extents(root->fs_info); 4651 btrfs_destroy_all_ordered_extents(fs_info);
4634 btrfs_destroy_delayed_inodes(root); 4652 btrfs_destroy_delayed_inodes(root);
4635 btrfs_assert_delayed_root_empty(root); 4653 btrfs_assert_delayed_root_empty(root);
4636 btrfs_destroy_pinned_extent(root, root->fs_info->pinned_extents); 4654 btrfs_destroy_pinned_extent(root, fs_info->pinned_extents);
4637 btrfs_destroy_all_delalloc_inodes(root->fs_info); 4655 btrfs_destroy_all_delalloc_inodes(fs_info);
4638 mutex_unlock(&root->fs_info->transaction_kthread_mutex); 4656 mutex_unlock(&fs_info->transaction_kthread_mutex);
4639 4657
4640 return 0; 4658 return 0;
4641} 4659}