disk-io.c (a1b32a5932cfac7c38b442582285f3da2a09dfd8) | disk-io.c (e02119d5a7b4396c5a872582fddc8bd6d305a70a) |
---|---|
1/* 2 * Copyright (C) 2007 Oracle. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public 6 * License v2 as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, --- 27 unchanged lines hidden (view full) --- 36#include "disk-io.h" 37#include "transaction.h" 38#include "btrfs_inode.h" 39#include "volumes.h" 40#include "print-tree.h" 41#include "async-thread.h" 42#include "locking.h" 43#include "ref-cache.h" | 1/* 2 * Copyright (C) 2007 Oracle. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public 6 * License v2 as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, --- 27 unchanged lines hidden (view full) --- 36#include "disk-io.h" 37#include "transaction.h" 38#include "btrfs_inode.h" 39#include "volumes.h" 40#include "print-tree.h" 41#include "async-thread.h" 42#include "locking.h" 43#include "ref-cache.h" |
44#include "tree-log.h" |
|
44 45#if 0 46static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf) 47{ 48 if (extent_buffer_blocknr(buf) != btrfs_header_blocknr(buf)) { 49 printk(KERN_CRIT "buf blocknr(buf) is %llu, header is %llu\n", 50 (unsigned long long)extent_buffer_blocknr(buf), 51 (unsigned long long)btrfs_header_blocknr(buf)); --- 637 unchanged lines hidden (view full) --- 689 struct extent_buffer *eb; 690 691 eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree, 692 bytenr, blocksize, NULL, GFP_NOFS); 693 return eb; 694} 695 696 | 45 46#if 0 47static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf) 48{ 49 if (extent_buffer_blocknr(buf) != btrfs_header_blocknr(buf)) { 50 printk(KERN_CRIT "buf blocknr(buf) is %llu, header is %llu\n", 51 (unsigned long long)extent_buffer_blocknr(buf), 52 (unsigned long long)btrfs_header_blocknr(buf)); --- 637 unchanged lines hidden (view full) --- 690 struct extent_buffer *eb; 691 692 eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree, 693 bytenr, blocksize, NULL, GFP_NOFS); 694 return eb; 695} 696 697 |
698int btrfs_write_tree_block(struct extent_buffer *buf) 699{ 700 return btrfs_fdatawrite_range(buf->first_page->mapping, buf->start, 701 buf->start + buf->len - 1, WB_SYNC_NONE); 702} 703 704int btrfs_wait_tree_block_writeback(struct extent_buffer *buf) 705{ 706 return btrfs_wait_on_page_writeback_range(buf->first_page->mapping, 707 buf->start, buf->start + buf->len -1); 708} 709 |
|
697struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr, 698 u32 blocksize, u64 parent_transid) 699{ 700 struct extent_buffer *buf = NULL; 701 struct inode *btree_inode = root->fs_info->btree_inode; 702 struct extent_io_tree *io_tree; 703 int ret; 704 --- 22 unchanged lines hidden (view full) --- 727 root->fs_info->running_transaction->transid) { 728 WARN_ON(!btrfs_tree_locked(buf)); 729 clear_extent_buffer_dirty(&BTRFS_I(btree_inode)->io_tree, 730 buf); 731 } 732 return 0; 733} 734 | 710struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr, 711 u32 blocksize, u64 parent_transid) 712{ 713 struct extent_buffer *buf = NULL; 714 struct inode *btree_inode = root->fs_info->btree_inode; 715 struct extent_io_tree *io_tree; 716 int ret; 717 --- 22 unchanged lines hidden (view full) --- 740 root->fs_info->running_transaction->transid) { 741 WARN_ON(!btrfs_tree_locked(buf)); 742 clear_extent_buffer_dirty(&BTRFS_I(btree_inode)->io_tree, 743 buf); 744 } 745 return 0; 746} 747 |
735int wait_on_tree_block_writeback(struct btrfs_root *root, 736 struct extent_buffer *buf) 737{ 738 struct inode *btree_inode = root->fs_info->btree_inode; 739 wait_on_extent_buffer_writeback(&BTRFS_I(btree_inode)->io_tree, 740 buf); 741 return 0; 742} 743 | |
744static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, 745 u32 stripesize, struct btrfs_root *root, 746 struct btrfs_fs_info *fs_info, 747 u64 objectid) 748{ 749 root->node = NULL; 750 root->inode = NULL; 751 root->commit_root = NULL; --- 14 unchanged lines hidden (view full) --- 766 root->in_sysfs = 0; 767 768 INIT_LIST_HEAD(&root->dirty_list); 769 INIT_LIST_HEAD(&root->orphan_list); 770 INIT_LIST_HEAD(&root->dead_list); 771 spin_lock_init(&root->node_lock); 772 spin_lock_init(&root->list_lock); 773 mutex_init(&root->objectid_mutex); | 748static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, 749 u32 stripesize, struct btrfs_root *root, 750 struct btrfs_fs_info *fs_info, 751 u64 objectid) 752{ 753 root->node = NULL; 754 root->inode = NULL; 755 root->commit_root = NULL; --- 14 unchanged lines hidden (view full) --- 770 root->in_sysfs = 0; 771 772 INIT_LIST_HEAD(&root->dirty_list); 773 INIT_LIST_HEAD(&root->orphan_list); 774 INIT_LIST_HEAD(&root->dead_list); 775 spin_lock_init(&root->node_lock); 776 spin_lock_init(&root->list_lock); 777 mutex_init(&root->objectid_mutex); |
778 mutex_init(&root->log_mutex); |
|
774 775 btrfs_leaf_ref_tree_init(&root->ref_tree_struct); 776 root->ref_tree = &root->ref_tree_struct; 777 778 memset(&root->root_key, 0, sizeof(root->root_key)); 779 memset(&root->root_item, 0, sizeof(root->root_item)); 780 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); 781 memset(&root->root_kobj, 0, sizeof(root->root_kobj)); --- 22 unchanged lines hidden (view full) --- 804 805 blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item)); 806 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), 807 blocksize, 0); 808 BUG_ON(!root->node); 809 return 0; 810} 811 | 779 780 btrfs_leaf_ref_tree_init(&root->ref_tree_struct); 781 root->ref_tree = &root->ref_tree_struct; 782 783 memset(&root->root_key, 0, sizeof(root->root_key)); 784 memset(&root->root_item, 0, sizeof(root->root_item)); 785 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress)); 786 memset(&root->root_kobj, 0, sizeof(root->root_kobj)); --- 22 unchanged lines hidden (view full) --- 809 810 blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item)); 811 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), 812 blocksize, 0); 813 BUG_ON(!root->node); 814 return 0; 815} 816 |
812struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_fs_info *fs_info, 813 struct btrfs_key *location) | 817int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans, 818 struct btrfs_fs_info *fs_info) |
814{ | 819{ |
820 struct extent_buffer *eb; 821 int ret; 822 823 if (!fs_info->log_root_tree) 824 return 0; 825 826 eb = fs_info->log_root_tree->node; 827 828 WARN_ON(btrfs_header_level(eb) != 0); 829 WARN_ON(btrfs_header_nritems(eb) != 0); 830 831 ret = btrfs_free_extent(trans, fs_info->tree_root, 832 eb->start, eb->len, 833 BTRFS_TREE_LOG_OBJECTID, 0, 0, 0, 1); 834 BUG_ON(ret); 835 836 free_extent_buffer(eb); 837 kfree(fs_info->log_root_tree); 838 fs_info->log_root_tree = NULL; 839 return 0; 840} 841 842int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans, 843 struct btrfs_fs_info *fs_info) 844{ |
|
815 struct btrfs_root *root; 816 struct btrfs_root *tree_root = fs_info->tree_root; | 845 struct btrfs_root *root; 846 struct btrfs_root *tree_root = fs_info->tree_root; |
847 848 root = kzalloc(sizeof(*root), GFP_NOFS); 849 if (!root) 850 return -ENOMEM; 851 852 __setup_root(tree_root->nodesize, tree_root->leafsize, 853 tree_root->sectorsize, tree_root->stripesize, 854 root, fs_info, BTRFS_TREE_LOG_OBJECTID); 855 856 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID; 857 root->root_key.type = BTRFS_ROOT_ITEM_KEY; 858 root->root_key.offset = BTRFS_TREE_LOG_OBJECTID; 859 root->ref_cows = 0; 860 861 root->node = btrfs_alloc_free_block(trans, root, root->leafsize, 862 BTRFS_TREE_LOG_OBJECTID, 863 0, 0, 0, 0, 0); 864 865 btrfs_set_header_nritems(root->node, 0); 866 btrfs_set_header_level(root->node, 0); 867 btrfs_set_header_bytenr(root->node, root->node->start); 868 btrfs_set_header_generation(root->node, trans->transid); 869 btrfs_set_header_owner(root->node, BTRFS_TREE_LOG_OBJECTID); 870 871 write_extent_buffer(root->node, root->fs_info->fsid, 872 (unsigned long)btrfs_header_fsid(root->node), 873 BTRFS_FSID_SIZE); 874 btrfs_mark_buffer_dirty(root->node); 875 btrfs_tree_unlock(root->node); 876 fs_info->log_root_tree = root; 877 return 0; 878} 879 880struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_root *tree_root, 881 struct btrfs_key *location) 882{ 883 struct btrfs_root *root; 884 struct btrfs_fs_info *fs_info = tree_root->fs_info; |
|
817 struct btrfs_path *path; 818 struct extent_buffer *l; 819 u64 highest_inode; 820 u32 blocksize; 821 int ret = 0; 822 823 root = kzalloc(sizeof(*root), GFP_NOFS); 824 if (!root) --- 33 unchanged lines hidden (view full) --- 858 kfree(root); 859 return ERR_PTR(ret); 860 } 861 blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item)); 862 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), 863 blocksize, 0); 864 BUG_ON(!root->node); 865insert: | 885 struct btrfs_path *path; 886 struct extent_buffer *l; 887 u64 highest_inode; 888 u32 blocksize; 889 int ret = 0; 890 891 root = kzalloc(sizeof(*root), GFP_NOFS); 892 if (!root) --- 33 unchanged lines hidden (view full) --- 926 kfree(root); 927 return ERR_PTR(ret); 928 } 929 blocksize = btrfs_level_size(root, btrfs_root_level(&root->root_item)); 930 root->node = read_tree_block(root, btrfs_root_bytenr(&root->root_item), 931 blocksize, 0); 932 BUG_ON(!root->node); 933insert: |
866 root->ref_cows = 1; 867 ret = btrfs_find_highest_inode(root, &highest_inode); 868 if (ret == 0) { 869 root->highest_inode = highest_inode; 870 root->last_inode_alloc = highest_inode; | 934 if (location->objectid != BTRFS_TREE_LOG_OBJECTID) { 935 root->ref_cows = 1; 936 ret = btrfs_find_highest_inode(root, &highest_inode); 937 if (ret == 0) { 938 root->highest_inode = highest_inode; 939 root->last_inode_alloc = highest_inode; 940 } |
871 } 872 return root; 873} 874 875struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info, 876 u64 root_objectid) 877{ 878 struct btrfs_root *root; --- 23 unchanged lines hidden (view full) --- 902 if (location->objectid == BTRFS_DEV_TREE_OBJECTID) 903 return fs_info->dev_root; 904 905 root = radix_tree_lookup(&fs_info->fs_roots_radix, 906 (unsigned long)location->objectid); 907 if (root) 908 return root; 909 | 941 } 942 return root; 943} 944 945struct btrfs_root *btrfs_lookup_fs_root(struct btrfs_fs_info *fs_info, 946 u64 root_objectid) 947{ 948 struct btrfs_root *root; --- 23 unchanged lines hidden (view full) --- 972 if (location->objectid == BTRFS_DEV_TREE_OBJECTID) 973 return fs_info->dev_root; 974 975 root = radix_tree_lookup(&fs_info->fs_roots_radix, 976 (unsigned long)location->objectid); 977 if (root) 978 return root; 979 |
910 root = btrfs_read_fs_root_no_radix(fs_info, location); | 980 root = btrfs_read_fs_root_no_radix(fs_info->tree_root, location); |
911 if (IS_ERR(root)) 912 return root; 913 ret = radix_tree_insert(&fs_info->fs_roots_radix, 914 (unsigned long)root->root_key.objectid, 915 root); 916 if (ret) { 917 free_extent_buffer(root->node); 918 kfree(root); --- 326 unchanged lines hidden (view full) --- 1245 char *options) 1246{ 1247 u32 sectorsize; 1248 u32 nodesize; 1249 u32 leafsize; 1250 u32 blocksize; 1251 u32 stripesize; 1252 struct buffer_head *bh; | 981 if (IS_ERR(root)) 982 return root; 983 ret = radix_tree_insert(&fs_info->fs_roots_radix, 984 (unsigned long)root->root_key.objectid, 985 root); 986 if (ret) { 987 free_extent_buffer(root->node); 988 kfree(root); --- 326 unchanged lines hidden (view full) --- 1315 char *options) 1316{ 1317 u32 sectorsize; 1318 u32 nodesize; 1319 u32 leafsize; 1320 u32 blocksize; 1321 u32 stripesize; 1322 struct buffer_head *bh; |
1253 struct btrfs_root *extent_root = kmalloc(sizeof(struct btrfs_root), | 1323 struct btrfs_root *extent_root = kzalloc(sizeof(struct btrfs_root), |
1254 GFP_NOFS); | 1324 GFP_NOFS); |
1255 struct btrfs_root *tree_root = kmalloc(sizeof(struct btrfs_root), | 1325 struct btrfs_root *tree_root = kzalloc(sizeof(struct btrfs_root), |
1256 GFP_NOFS); 1257 struct btrfs_fs_info *fs_info = kzalloc(sizeof(*fs_info), 1258 GFP_NOFS); | 1326 GFP_NOFS); 1327 struct btrfs_fs_info *fs_info = kzalloc(sizeof(*fs_info), 1328 GFP_NOFS); |
1259 struct btrfs_root *chunk_root = kmalloc(sizeof(struct btrfs_root), | 1329 struct btrfs_root *chunk_root = kzalloc(sizeof(struct btrfs_root), |
1260 GFP_NOFS); | 1330 GFP_NOFS); |
1261 struct btrfs_root *dev_root = kmalloc(sizeof(struct btrfs_root), | 1331 struct btrfs_root *dev_root = kzalloc(sizeof(struct btrfs_root), |
1262 GFP_NOFS); | 1332 GFP_NOFS); |
1333 struct btrfs_root *log_tree_root; 1334 |
|
1263 int ret; 1264 int err = -EINVAL; 1265 1266 struct btrfs_super_block *disk_super; 1267 1268 if (!extent_root || !tree_root || !fs_info) { 1269 err = -ENOMEM; 1270 goto fail; --- 67 unchanged lines hidden (view full) --- 1338 1339 BTRFS_I(fs_info->btree_inode)->root = tree_root; 1340 memset(&BTRFS_I(fs_info->btree_inode)->location, 0, 1341 sizeof(struct btrfs_key)); 1342 insert_inode_hash(fs_info->btree_inode); 1343 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); 1344 1345 mutex_init(&fs_info->trans_mutex); | 1335 int ret; 1336 int err = -EINVAL; 1337 1338 struct btrfs_super_block *disk_super; 1339 1340 if (!extent_root || !tree_root || !fs_info) { 1341 err = -ENOMEM; 1342 goto fail; --- 67 unchanged lines hidden (view full) --- 1410 1411 BTRFS_I(fs_info->btree_inode)->root = tree_root; 1412 memset(&BTRFS_I(fs_info->btree_inode)->location, 0, 1413 sizeof(struct btrfs_key)); 1414 insert_inode_hash(fs_info->btree_inode); 1415 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); 1416 1417 mutex_init(&fs_info->trans_mutex); |
1418 mutex_init(&fs_info->tree_log_mutex); |
|
1346 mutex_init(&fs_info->drop_mutex); 1347 mutex_init(&fs_info->alloc_mutex); 1348 mutex_init(&fs_info->chunk_mutex); 1349 mutex_init(&fs_info->transaction_kthread_mutex); 1350 mutex_init(&fs_info->cleaner_mutex); 1351 mutex_init(&fs_info->volume_mutex); 1352 init_waitqueue_head(&fs_info->transaction_throttle); 1353 init_waitqueue_head(&fs_info->transaction_wait); 1354 init_waitqueue_head(&fs_info->async_submit_wait); | 1419 mutex_init(&fs_info->drop_mutex); 1420 mutex_init(&fs_info->alloc_mutex); 1421 mutex_init(&fs_info->chunk_mutex); 1422 mutex_init(&fs_info->transaction_kthread_mutex); 1423 mutex_init(&fs_info->cleaner_mutex); 1424 mutex_init(&fs_info->volume_mutex); 1425 init_waitqueue_head(&fs_info->transaction_throttle); 1426 init_waitqueue_head(&fs_info->transaction_wait); 1427 init_waitqueue_head(&fs_info->async_submit_wait); |
1428 init_waitqueue_head(&fs_info->tree_log_wait); 1429 atomic_set(&fs_info->tree_log_commit, 0); 1430 atomic_set(&fs_info->tree_log_writers, 0); 1431 fs_info->tree_log_transid = 0; |
|
1355 1356#if 0 1357 ret = add_hasher(fs_info, "crc32c"); 1358 if (ret) { 1359 printk("btrfs: failed hash setup, modprobe cryptomgr?\n"); 1360 err = -ENOMEM; 1361 goto fail_iput; 1362 } --- 164 unchanged lines hidden (view full) --- 1527 goto fail_extent_root; 1528 1529 fs_info->transaction_kthread = kthread_run(transaction_kthread, 1530 tree_root, 1531 "btrfs-transaction"); 1532 if (!fs_info->transaction_kthread) 1533 goto fail_cleaner; 1534 | 1432 1433#if 0 1434 ret = add_hasher(fs_info, "crc32c"); 1435 if (ret) { 1436 printk("btrfs: failed hash setup, modprobe cryptomgr?\n"); 1437 err = -ENOMEM; 1438 goto fail_iput; 1439 } --- 164 unchanged lines hidden (view full) --- 1604 goto fail_extent_root; 1605 1606 fs_info->transaction_kthread = kthread_run(transaction_kthread, 1607 tree_root, 1608 "btrfs-transaction"); 1609 if (!fs_info->transaction_kthread) 1610 goto fail_cleaner; 1611 |
1612 if (btrfs_super_log_root(disk_super) != 0) { 1613 u32 blocksize; 1614 u64 bytenr = btrfs_super_log_root(disk_super); |
|
1535 | 1615 |
1616 blocksize = 1617 btrfs_level_size(tree_root, 1618 btrfs_super_log_root_level(disk_super)); 1619 1620 log_tree_root = kzalloc(sizeof(struct btrfs_root), 1621 GFP_NOFS); 1622 1623 __setup_root(nodesize, leafsize, sectorsize, stripesize, 1624 log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID); 1625 1626 log_tree_root->node = read_tree_block(tree_root, bytenr, 1627 blocksize, 0); 1628 ret = btrfs_recover_log_trees(log_tree_root); 1629 BUG_ON(ret); 1630 } 1631 fs_info->last_trans_committed = btrfs_super_generation(disk_super); |
|
1536 return tree_root; 1537 1538fail_cleaner: 1539 kthread_stop(fs_info->cleaner_kthread); 1540fail_extent_root: 1541 free_extent_buffer(extent_root->node); 1542fail_tree_root: 1543 free_extent_buffer(tree_root->node); --- 368 unchanged lines hidden --- | 1632 return tree_root; 1633 1634fail_cleaner: 1635 kthread_stop(fs_info->cleaner_kthread); 1636fail_extent_root: 1637 free_extent_buffer(extent_root->node); 1638fail_tree_root: 1639 free_extent_buffer(tree_root->node); --- 368 unchanged lines hidden --- |