aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c104
1 files changed, 77 insertions, 27 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 81a313874ae5..7feac5a475e9 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -16,7 +16,6 @@
16 * Boston, MA 021110-1307, USA. 16 * Boston, MA 021110-1307, USA.
17 */ 17 */
18 18
19#include <linux/version.h>
20#include <linux/fs.h> 19#include <linux/fs.h>
21#include <linux/blkdev.h> 20#include <linux/blkdev.h>
22#include <linux/scatterlist.h> 21#include <linux/scatterlist.h>
@@ -850,6 +849,14 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
850 spin_lock_init(&root->list_lock); 849 spin_lock_init(&root->list_lock);
851 mutex_init(&root->objectid_mutex); 850 mutex_init(&root->objectid_mutex);
852 mutex_init(&root->log_mutex); 851 mutex_init(&root->log_mutex);
852 init_waitqueue_head(&root->log_writer_wait);
853 init_waitqueue_head(&root->log_commit_wait[0]);
854 init_waitqueue_head(&root->log_commit_wait[1]);
855 atomic_set(&root->log_commit[0], 0);
856 atomic_set(&root->log_commit[1], 0);
857 atomic_set(&root->log_writers, 0);
858 root->log_batch = 0;
859 root->log_transid = 0;
853 extent_io_tree_init(&root->dirty_log_pages, 860 extent_io_tree_init(&root->dirty_log_pages,
854 fs_info->btree_inode->i_mapping, GFP_NOFS); 861 fs_info->btree_inode->i_mapping, GFP_NOFS);
855 862
@@ -934,15 +941,16 @@ int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans,
934 return 0; 941 return 0;
935} 942}
936 943
937int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans, 944static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
938 struct btrfs_fs_info *fs_info) 945 struct btrfs_fs_info *fs_info)
939{ 946{
940 struct btrfs_root *root; 947 struct btrfs_root *root;
941 struct btrfs_root *tree_root = fs_info->tree_root; 948 struct btrfs_root *tree_root = fs_info->tree_root;
949 struct extent_buffer *leaf;
942 950
943 root = kzalloc(sizeof(*root), GFP_NOFS); 951 root = kzalloc(sizeof(*root), GFP_NOFS);
944 if (!root) 952 if (!root)
945 return -ENOMEM; 953 return ERR_PTR(-ENOMEM);
946 954
947 __setup_root(tree_root->nodesize, tree_root->leafsize, 955 __setup_root(tree_root->nodesize, tree_root->leafsize,
948 tree_root->sectorsize, tree_root->stripesize, 956 tree_root->sectorsize, tree_root->stripesize,
@@ -951,12 +959,23 @@ int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
951 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID; 959 root->root_key.objectid = BTRFS_TREE_LOG_OBJECTID;
952 root->root_key.type = BTRFS_ROOT_ITEM_KEY; 960 root->root_key.type = BTRFS_ROOT_ITEM_KEY;
953 root->root_key.offset = BTRFS_TREE_LOG_OBJECTID; 961 root->root_key.offset = BTRFS_TREE_LOG_OBJECTID;
962 /*
963 * log trees do not get reference counted because they go away
964 * before a real commit is actually done. They do store pointers
965 * to file data extents, and those reference counts still get
966 * updated (along with back refs to the log tree).
967 */
954 root->ref_cows = 0; 968 root->ref_cows = 0;
955 969
956 root->node = btrfs_alloc_free_block(trans, root, root->leafsize, 970 leaf = btrfs_alloc_free_block(trans, root, root->leafsize,
957 0, BTRFS_TREE_LOG_OBJECTID, 971 0, BTRFS_TREE_LOG_OBJECTID,
958 trans->transid, 0, 0, 0); 972 trans->transid, 0, 0, 0);
973 if (IS_ERR(leaf)) {
974 kfree(root);
975 return ERR_CAST(leaf);
976 }
959 977
978 root->node = leaf;
960 btrfs_set_header_nritems(root->node, 0); 979 btrfs_set_header_nritems(root->node, 0);
961 btrfs_set_header_level(root->node, 0); 980 btrfs_set_header_level(root->node, 0);
962 btrfs_set_header_bytenr(root->node, root->node->start); 981 btrfs_set_header_bytenr(root->node, root->node->start);
@@ -968,7 +987,48 @@ int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
968 BTRFS_FSID_SIZE); 987 BTRFS_FSID_SIZE);
969 btrfs_mark_buffer_dirty(root->node); 988 btrfs_mark_buffer_dirty(root->node);
970 btrfs_tree_unlock(root->node); 989 btrfs_tree_unlock(root->node);
971 fs_info->log_root_tree = root; 990 return root;
991}
992
993int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
994 struct btrfs_fs_info *fs_info)
995{
996 struct btrfs_root *log_root;
997
998 log_root = alloc_log_tree(trans, fs_info);
999 if (IS_ERR(log_root))
1000 return PTR_ERR(log_root);
1001 WARN_ON(fs_info->log_root_tree);
1002 fs_info->log_root_tree = log_root;
1003 return 0;
1004}
1005
1006int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
1007 struct btrfs_root *root)
1008{
1009 struct btrfs_root *log_root;
1010 struct btrfs_inode_item *inode_item;
1011
1012 log_root = alloc_log_tree(trans, root->fs_info);
1013 if (IS_ERR(log_root))
1014 return PTR_ERR(log_root);
1015
1016 log_root->last_trans = trans->transid;
1017 log_root->root_key.offset = root->root_key.objectid;
1018
1019 inode_item = &log_root->root_item.inode;
1020 inode_item->generation = cpu_to_le64(1);
1021 inode_item->size = cpu_to_le64(3);
1022 inode_item->nlink = cpu_to_le32(1);
1023 inode_item->nbytes = cpu_to_le64(root->leafsize);
1024 inode_item->mode = cpu_to_le32(S_IFDIR | 0755);
1025
1026 btrfs_set_root_bytenr(&log_root->root_item, log_root->node->start);
1027 btrfs_set_root_generation(&log_root->root_item, trans->transid);
1028
1029 WARN_ON(root->log_root);
1030 root->log_root = log_root;
1031 root->log_transid = 0;
972 return 0; 1032 return 0;
973} 1033}
974 1034
@@ -1136,7 +1196,6 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
1136{ 1196{
1137 struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data; 1197 struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data;
1138 int ret = 0; 1198 int ret = 0;
1139 struct list_head *cur;
1140 struct btrfs_device *device; 1199 struct btrfs_device *device;
1141 struct backing_dev_info *bdi; 1200 struct backing_dev_info *bdi;
1142#if 0 1201#if 0
@@ -1144,8 +1203,7 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
1144 btrfs_congested_async(info, 0)) 1203 btrfs_congested_async(info, 0))
1145 return 1; 1204 return 1;
1146#endif 1205#endif
1147 list_for_each(cur, &info->fs_devices->devices) { 1206 list_for_each_entry(device, &info->fs_devices->devices, dev_list) {
1148 device = list_entry(cur, struct btrfs_device, dev_list);
1149 if (!device->bdev) 1207 if (!device->bdev)
1150 continue; 1208 continue;
1151 bdi = blk_get_backing_dev_info(device->bdev); 1209 bdi = blk_get_backing_dev_info(device->bdev);
@@ -1163,13 +1221,11 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
1163 */ 1221 */
1164static void __unplug_io_fn(struct backing_dev_info *bdi, struct page *page) 1222static void __unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
1165{ 1223{
1166 struct list_head *cur;
1167 struct btrfs_device *device; 1224 struct btrfs_device *device;
1168 struct btrfs_fs_info *info; 1225 struct btrfs_fs_info *info;
1169 1226
1170 info = (struct btrfs_fs_info *)bdi->unplug_io_data; 1227 info = (struct btrfs_fs_info *)bdi->unplug_io_data;
1171 list_for_each(cur, &info->fs_devices->devices) { 1228 list_for_each_entry(device, &info->fs_devices->devices, dev_list) {
1172 device = list_entry(cur, struct btrfs_device, dev_list);
1173 if (!device->bdev) 1229 if (!device->bdev)
1174 continue; 1230 continue;
1175 1231
@@ -1535,10 +1591,6 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1535 init_waitqueue_head(&fs_info->transaction_throttle); 1591 init_waitqueue_head(&fs_info->transaction_throttle);
1536 init_waitqueue_head(&fs_info->transaction_wait); 1592 init_waitqueue_head(&fs_info->transaction_wait);
1537 init_waitqueue_head(&fs_info->async_submit_wait); 1593 init_waitqueue_head(&fs_info->async_submit_wait);
1538 init_waitqueue_head(&fs_info->tree_log_wait);
1539 atomic_set(&fs_info->tree_log_commit, 0);
1540 atomic_set(&fs_info->tree_log_writers, 0);
1541 fs_info->tree_log_transid = 0;
1542 1594
1543 __setup_root(4096, 4096, 4096, 4096, tree_root, 1595 __setup_root(4096, 4096, 4096, 4096, tree_root,
1544 fs_info, BTRFS_ROOT_TREE_OBJECTID); 1596 fs_info, BTRFS_ROOT_TREE_OBJECTID);
@@ -1740,13 +1792,13 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1740 fs_info->system_alloc_profile = fs_info->metadata_alloc_profile; 1792 fs_info->system_alloc_profile = fs_info->metadata_alloc_profile;
1741 fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, 1793 fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root,
1742 "btrfs-cleaner"); 1794 "btrfs-cleaner");
1743 if (!fs_info->cleaner_kthread) 1795 if (IS_ERR(fs_info->cleaner_kthread))
1744 goto fail_csum_root; 1796 goto fail_csum_root;
1745 1797
1746 fs_info->transaction_kthread = kthread_run(transaction_kthread, 1798 fs_info->transaction_kthread = kthread_run(transaction_kthread,
1747 tree_root, 1799 tree_root,
1748 "btrfs-transaction"); 1800 "btrfs-transaction");
1749 if (!fs_info->transaction_kthread) 1801 if (IS_ERR(fs_info->transaction_kthread))
1750 goto fail_cleaner; 1802 goto fail_cleaner;
1751 1803
1752 if (btrfs_super_log_root(disk_super) != 0) { 1804 if (btrfs_super_log_root(disk_super) != 0) {
@@ -1828,13 +1880,14 @@ fail_sb_buffer:
1828fail_iput: 1880fail_iput:
1829 invalidate_inode_pages2(fs_info->btree_inode->i_mapping); 1881 invalidate_inode_pages2(fs_info->btree_inode->i_mapping);
1830 iput(fs_info->btree_inode); 1882 iput(fs_info->btree_inode);
1831fail: 1883
1832 btrfs_close_devices(fs_info->fs_devices); 1884 btrfs_close_devices(fs_info->fs_devices);
1833 btrfs_mapping_tree_free(&fs_info->mapping_tree); 1885 btrfs_mapping_tree_free(&fs_info->mapping_tree);
1886 bdi_destroy(&fs_info->bdi);
1834 1887
1888fail:
1835 kfree(extent_root); 1889 kfree(extent_root);
1836 kfree(tree_root); 1890 kfree(tree_root);
1837 bdi_destroy(&fs_info->bdi);
1838 kfree(fs_info); 1891 kfree(fs_info);
1839 kfree(chunk_root); 1892 kfree(chunk_root);
1840 kfree(dev_root); 1893 kfree(dev_root);
@@ -1995,7 +2048,6 @@ static int write_dev_supers(struct btrfs_device *device,
1995 2048
1996int write_all_supers(struct btrfs_root *root, int max_mirrors) 2049int write_all_supers(struct btrfs_root *root, int max_mirrors)
1997{ 2050{
1998 struct list_head *cur;
1999 struct list_head *head = &root->fs_info->fs_devices->devices; 2051 struct list_head *head = &root->fs_info->fs_devices->devices;
2000 struct btrfs_device *dev; 2052 struct btrfs_device *dev;
2001 struct btrfs_super_block *sb; 2053 struct btrfs_super_block *sb;
@@ -2011,8 +2063,7 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors)
2011 2063
2012 sb = &root->fs_info->super_for_commit; 2064 sb = &root->fs_info->super_for_commit;
2013 dev_item = &sb->dev_item; 2065 dev_item = &sb->dev_item;
2014 list_for_each(cur, head) { 2066 list_for_each_entry(dev, head, dev_list) {
2015 dev = list_entry(cur, struct btrfs_device, dev_list);
2016 if (!dev->bdev) { 2067 if (!dev->bdev) {
2017 total_errors++; 2068 total_errors++;
2018 continue; 2069 continue;
@@ -2045,8 +2096,7 @@ int write_all_supers(struct btrfs_root *root, int max_mirrors)
2045 } 2096 }
2046 2097
2047 total_errors = 0; 2098 total_errors = 0;
2048 list_for_each(cur, head) { 2099 list_for_each_entry(dev, head, dev_list) {
2049 dev = list_entry(cur, struct btrfs_device, dev_list);
2050 if (!dev->bdev) 2100 if (!dev->bdev)
2051 continue; 2101 continue;
2052 if (!dev->in_fs_metadata || !dev->writeable) 2102 if (!dev->in_fs_metadata || !dev->writeable)