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.c61
1 files changed, 35 insertions, 26 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index fc8dfaa27967..07d9e83f8954 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;
@@ -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;
@@ -733,20 +752,12 @@ static void end_workqueue_bio(struct bio *bio, int err)
733 btrfs_queue_work(wq, &end_io_wq->work); 752 btrfs_queue_work(wq, &end_io_wq->work);
734} 753}
735 754
736/*
737 * For the metadata arg you want
738 *
739 * 0 - if data
740 * 1 - if normal metadta
741 * 2 - if writing to the free space cache area
742 * 3 - raid parity work
743 */
744int 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,
745 int metadata) 756 enum btrfs_wq_endio_type metadata)
746{ 757{
747 struct end_io_wq *end_io_wq; 758 struct btrfs_end_io_wq *end_io_wq;
748 759
749 end_io_wq = kmalloc(sizeof(*end_io_wq), GFP_NOFS); 760 end_io_wq = kmem_cache_alloc(btrfs_end_io_wq_cache, GFP_NOFS);
750 if (!end_io_wq) 761 if (!end_io_wq)
751 return -ENOMEM; 762 return -ENOMEM;
752 763
@@ -930,7 +941,7 @@ static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
930 * can happen in the async kernel threads 941 * can happen in the async kernel threads
931 */ 942 */
932 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,
933 bio, 1); 944 bio, BTRFS_WQ_ENDIO_METADATA);
934 if (ret) 945 if (ret)
935 goto out_w_error; 946 goto out_w_error;
936 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, 947 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio,
@@ -1119,11 +1130,9 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
1119struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, 1130struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
1120 u64 bytenr, u32 blocksize) 1131 u64 bytenr, u32 blocksize)
1121{ 1132{
1122#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS 1133 if (btrfs_test_is_dummy_root(root))
1123 if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state)))
1124 return alloc_test_extent_buffer(root->fs_info, bytenr, 1134 return alloc_test_extent_buffer(root->fs_info, bytenr,
1125 blocksize); 1135 blocksize);
1126#endif
1127 return alloc_extent_buffer(root->fs_info, bytenr, blocksize); 1136 return alloc_extent_buffer(root->fs_info, bytenr, blocksize);
1128} 1137}
1129 1138
@@ -1731,16 +1740,16 @@ static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi)
1731static void end_workqueue_fn(struct btrfs_work *work) 1740static void end_workqueue_fn(struct btrfs_work *work)
1732{ 1741{
1733 struct bio *bio; 1742 struct bio *bio;
1734 struct end_io_wq *end_io_wq; 1743 struct btrfs_end_io_wq *end_io_wq;
1735 int error; 1744 int error;
1736 1745
1737 end_io_wq = container_of(work, struct end_io_wq, work); 1746 end_io_wq = container_of(work, struct btrfs_end_io_wq, work);
1738 bio = end_io_wq->bio; 1747 bio = end_io_wq->bio;
1739 1748
1740 error = end_io_wq->error; 1749 error = end_io_wq->error;
1741 bio->bi_private = end_io_wq->private; 1750 bio->bi_private = end_io_wq->private;
1742 bio->bi_end_io = end_io_wq->end_io; 1751 bio->bi_end_io = end_io_wq->end_io;
1743 kfree(end_io_wq); 1752 kmem_cache_free(btrfs_end_io_wq_cache, end_io_wq);
1744 bio_endio_nodec(bio, error); 1753 bio_endio_nodec(bio, error);
1745} 1754}
1746 1755
@@ -2260,7 +2269,7 @@ int open_ctree(struct super_block *sb,
2260 atomic_set(&fs_info->qgroup_op_seq, 0); 2269 atomic_set(&fs_info->qgroup_op_seq, 0);
2261 atomic64_set(&fs_info->tree_mod_seq, 0); 2270 atomic64_set(&fs_info->tree_mod_seq, 0);
2262 fs_info->sb = sb; 2271 fs_info->sb = sb;
2263 fs_info->max_inline = 8192 * 1024; 2272 fs_info->max_inline = BTRFS_DEFAULT_MAX_INLINE;
2264 fs_info->metadata_ratio = 0; 2273 fs_info->metadata_ratio = 0;
2265 fs_info->defrag_inodes = RB_ROOT; 2274 fs_info->defrag_inodes = RB_ROOT;
2266 fs_info->free_chunk_space = 0; 2275 fs_info->free_chunk_space = 0;