diff options
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 009e3bd18f23..feca04197d02 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/kthread.h> | 27 | #include <linux/kthread.h> |
28 | #include <linux/freezer.h> | 28 | #include <linux/freezer.h> |
29 | #include <linux/crc32c.h> | 29 | #include <linux/crc32c.h> |
30 | #include <linux/slab.h> | ||
30 | #include "compat.h" | 31 | #include "compat.h" |
31 | #include "ctree.h" | 32 | #include "ctree.h" |
32 | #include "disk-io.h" | 33 | #include "disk-io.h" |
@@ -43,8 +44,6 @@ static struct extent_io_ops btree_extent_io_ops; | |||
43 | static void end_workqueue_fn(struct btrfs_work *work); | 44 | static void end_workqueue_fn(struct btrfs_work *work); |
44 | static void free_fs_root(struct btrfs_root *root); | 45 | static void free_fs_root(struct btrfs_root *root); |
45 | 46 | ||
46 | static atomic_t btrfs_bdi_num = ATOMIC_INIT(0); | ||
47 | |||
48 | /* | 47 | /* |
49 | * end_io_wq structs are used to do processing in task context when an IO is | 48 | * end_io_wq structs are used to do processing in task context when an IO is |
50 | * complete. This is used during reads to verify checksums, and it is used | 49 | * complete. This is used during reads to verify checksums, and it is used |
@@ -263,13 +262,15 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, | |||
263 | static int verify_parent_transid(struct extent_io_tree *io_tree, | 262 | static int verify_parent_transid(struct extent_io_tree *io_tree, |
264 | struct extent_buffer *eb, u64 parent_transid) | 263 | struct extent_buffer *eb, u64 parent_transid) |
265 | { | 264 | { |
265 | struct extent_state *cached_state = NULL; | ||
266 | int ret; | 266 | int ret; |
267 | 267 | ||
268 | if (!parent_transid || btrfs_header_generation(eb) == parent_transid) | 268 | if (!parent_transid || btrfs_header_generation(eb) == parent_transid) |
269 | return 0; | 269 | return 0; |
270 | 270 | ||
271 | lock_extent(io_tree, eb->start, eb->start + eb->len - 1, GFP_NOFS); | 271 | lock_extent_bits(io_tree, eb->start, eb->start + eb->len - 1, |
272 | if (extent_buffer_uptodate(io_tree, eb) && | 272 | 0, &cached_state, GFP_NOFS); |
273 | if (extent_buffer_uptodate(io_tree, eb, cached_state) && | ||
273 | btrfs_header_generation(eb) == parent_transid) { | 274 | btrfs_header_generation(eb) == parent_transid) { |
274 | ret = 0; | 275 | ret = 0; |
275 | goto out; | 276 | goto out; |
@@ -282,10 +283,10 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, | |||
282 | (unsigned long long)btrfs_header_generation(eb)); | 283 | (unsigned long long)btrfs_header_generation(eb)); |
283 | } | 284 | } |
284 | ret = 1; | 285 | ret = 1; |
285 | clear_extent_buffer_uptodate(io_tree, eb); | 286 | clear_extent_buffer_uptodate(io_tree, eb, &cached_state); |
286 | out: | 287 | out: |
287 | unlock_extent(io_tree, eb->start, eb->start + eb->len - 1, | 288 | unlock_extent_cached(io_tree, eb->start, eb->start + eb->len - 1, |
288 | GFP_NOFS); | 289 | &cached_state, GFP_NOFS); |
289 | return ret; | 290 | return ret; |
290 | } | 291 | } |
291 | 292 | ||
@@ -901,7 +902,7 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
901 | root->highest_objectid = 0; | 902 | root->highest_objectid = 0; |
902 | root->name = NULL; | 903 | root->name = NULL; |
903 | root->in_sysfs = 0; | 904 | root->in_sysfs = 0; |
904 | root->inode_tree.rb_node = NULL; | 905 | root->inode_tree = RB_ROOT; |
905 | 906 | ||
906 | INIT_LIST_HEAD(&root->dirty_list); | 907 | INIT_LIST_HEAD(&root->dirty_list); |
907 | INIT_LIST_HEAD(&root->orphan_list); | 908 | INIT_LIST_HEAD(&root->orphan_list); |
@@ -1372,19 +1373,11 @@ static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi) | |||
1372 | { | 1373 | { |
1373 | int err; | 1374 | int err; |
1374 | 1375 | ||
1375 | bdi->name = "btrfs"; | ||
1376 | bdi->capabilities = BDI_CAP_MAP_COPY; | 1376 | bdi->capabilities = BDI_CAP_MAP_COPY; |
1377 | err = bdi_init(bdi); | 1377 | err = bdi_setup_and_register(bdi, "btrfs", BDI_CAP_MAP_COPY); |
1378 | if (err) | 1378 | if (err) |
1379 | return err; | 1379 | return err; |
1380 | 1380 | ||
1381 | err = bdi_register(bdi, NULL, "btrfs-%d", | ||
1382 | atomic_inc_return(&btrfs_bdi_num)); | ||
1383 | if (err) { | ||
1384 | bdi_destroy(bdi); | ||
1385 | return err; | ||
1386 | } | ||
1387 | |||
1388 | bdi->ra_pages = default_backing_dev_info.ra_pages; | 1381 | bdi->ra_pages = default_backing_dev_info.ra_pages; |
1389 | bdi->unplug_io_fn = btrfs_unplug_io_fn; | 1382 | bdi->unplug_io_fn = btrfs_unplug_io_fn; |
1390 | bdi->unplug_io_data = info; | 1383 | bdi->unplug_io_data = info; |
@@ -1632,7 +1625,6 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1632 | atomic_set(&fs_info->async_submit_draining, 0); | 1625 | atomic_set(&fs_info->async_submit_draining, 0); |
1633 | atomic_set(&fs_info->nr_async_bios, 0); | 1626 | atomic_set(&fs_info->nr_async_bios, 0); |
1634 | fs_info->sb = sb; | 1627 | fs_info->sb = sb; |
1635 | fs_info->max_extent = (u64)-1; | ||
1636 | fs_info->max_inline = 8192 * 1024; | 1628 | fs_info->max_inline = 8192 * 1024; |
1637 | fs_info->metadata_ratio = 0; | 1629 | fs_info->metadata_ratio = 0; |
1638 | 1630 | ||
@@ -1673,7 +1665,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1673 | insert_inode_hash(fs_info->btree_inode); | 1665 | insert_inode_hash(fs_info->btree_inode); |
1674 | 1666 | ||
1675 | spin_lock_init(&fs_info->block_group_cache_lock); | 1667 | spin_lock_init(&fs_info->block_group_cache_lock); |
1676 | fs_info->block_group_cache_tree.rb_node = NULL; | 1668 | fs_info->block_group_cache_tree = RB_ROOT; |
1677 | 1669 | ||
1678 | extent_io_tree_init(&fs_info->freed_extents[0], | 1670 | extent_io_tree_init(&fs_info->freed_extents[0], |
1679 | fs_info->btree_inode->i_mapping, GFP_NOFS); | 1671 | fs_info->btree_inode->i_mapping, GFP_NOFS); |
@@ -1920,7 +1912,11 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1920 | 1912 | ||
1921 | csum_root->track_dirty = 1; | 1913 | csum_root->track_dirty = 1; |
1922 | 1914 | ||
1923 | btrfs_read_block_groups(extent_root); | 1915 | ret = btrfs_read_block_groups(extent_root); |
1916 | if (ret) { | ||
1917 | printk(KERN_ERR "Failed to read block groups: %d\n", ret); | ||
1918 | goto fail_block_groups; | ||
1919 | } | ||
1924 | 1920 | ||
1925 | fs_info->generation = generation; | 1921 | fs_info->generation = generation; |
1926 | fs_info->last_trans_committed = generation; | 1922 | fs_info->last_trans_committed = generation; |
@@ -1930,7 +1926,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1930 | fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, | 1926 | fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, |
1931 | "btrfs-cleaner"); | 1927 | "btrfs-cleaner"); |
1932 | if (IS_ERR(fs_info->cleaner_kthread)) | 1928 | if (IS_ERR(fs_info->cleaner_kthread)) |
1933 | goto fail_csum_root; | 1929 | goto fail_block_groups; |
1934 | 1930 | ||
1935 | fs_info->transaction_kthread = kthread_run(transaction_kthread, | 1931 | fs_info->transaction_kthread = kthread_run(transaction_kthread, |
1936 | tree_root, | 1932 | tree_root, |
@@ -1982,7 +1978,12 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1982 | 1978 | ||
1983 | if (!(sb->s_flags & MS_RDONLY)) { | 1979 | if (!(sb->s_flags & MS_RDONLY)) { |
1984 | ret = btrfs_recover_relocation(tree_root); | 1980 | ret = btrfs_recover_relocation(tree_root); |
1985 | BUG_ON(ret); | 1981 | if (ret < 0) { |
1982 | printk(KERN_WARNING | ||
1983 | "btrfs: failed to recover relocation\n"); | ||
1984 | err = -EINVAL; | ||
1985 | goto fail_trans_kthread; | ||
1986 | } | ||
1986 | } | 1987 | } |
1987 | 1988 | ||
1988 | location.objectid = BTRFS_FS_TREE_OBJECTID; | 1989 | location.objectid = BTRFS_FS_TREE_OBJECTID; |
@@ -1993,6 +1994,12 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1993 | if (!fs_info->fs_root) | 1994 | if (!fs_info->fs_root) |
1994 | goto fail_trans_kthread; | 1995 | goto fail_trans_kthread; |
1995 | 1996 | ||
1997 | if (!(sb->s_flags & MS_RDONLY)) { | ||
1998 | down_read(&fs_info->cleanup_work_sem); | ||
1999 | btrfs_orphan_cleanup(fs_info->fs_root); | ||
2000 | up_read(&fs_info->cleanup_work_sem); | ||
2001 | } | ||
2002 | |||
1996 | return tree_root; | 2003 | return tree_root; |
1997 | 2004 | ||
1998 | fail_trans_kthread: | 2005 | fail_trans_kthread: |
@@ -2007,7 +2014,8 @@ fail_cleaner: | |||
2007 | filemap_write_and_wait(fs_info->btree_inode->i_mapping); | 2014 | filemap_write_and_wait(fs_info->btree_inode->i_mapping); |
2008 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); | 2015 | invalidate_inode_pages2(fs_info->btree_inode->i_mapping); |
2009 | 2016 | ||
2010 | fail_csum_root: | 2017 | fail_block_groups: |
2018 | btrfs_free_block_groups(fs_info); | ||
2011 | free_extent_buffer(csum_root->node); | 2019 | free_extent_buffer(csum_root->node); |
2012 | free_extent_buffer(csum_root->commit_root); | 2020 | free_extent_buffer(csum_root->commit_root); |
2013 | fail_dev_root: | 2021 | fail_dev_root: |
@@ -2486,7 +2494,8 @@ int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid) | |||
2486 | int ret; | 2494 | int ret; |
2487 | struct inode *btree_inode = buf->first_page->mapping->host; | 2495 | struct inode *btree_inode = buf->first_page->mapping->host; |
2488 | 2496 | ||
2489 | ret = extent_buffer_uptodate(&BTRFS_I(btree_inode)->io_tree, buf); | 2497 | ret = extent_buffer_uptodate(&BTRFS_I(btree_inode)->io_tree, buf, |
2498 | NULL); | ||
2490 | if (!ret) | 2499 | if (!ret) |
2491 | return ret; | 2500 | return ret; |
2492 | 2501 | ||