aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/check-integrity.c2
-rw-r--r--fs/btrfs/extent-tree.c2
-rw-r--r--fs/btrfs/extent_io.c19
-rw-r--r--fs/btrfs/extent_io.h4
-rw-r--r--fs/btrfs/inode.c12
-rw-r--r--fs/btrfs/reada.c3
-rw-r--r--fs/btrfs/scrub.c14
-rw-r--r--fs/btrfs/volumes.c11
-rw-r--r--fs/btrfs/volumes.h2
9 files changed, 32 insertions, 37 deletions
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 58dfac1359a3..8f9abedae2c3 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -1582,7 +1582,7 @@ static int btrfsic_map_block(struct btrfsic_state *state, u64 bytenr, u32 len,
1582 struct btrfs_device *device; 1582 struct btrfs_device *device;
1583 1583
1584 length = len; 1584 length = len;
1585 ret = btrfs_map_block(&state->root->fs_info->mapping_tree, READ, 1585 ret = btrfs_map_block(state->root->fs_info, READ,
1586 bytenr, &length, &multi, mirror_num); 1586 bytenr, &length, &multi, mirror_num);
1587 1587
1588 device = multi->stripes[0].dev; 1588 device = multi->stripes[0].dev;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index f8a358aee060..b4d438f6c2b3 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1818,7 +1818,7 @@ static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr,
1818 1818
1819 1819
1820 /* Tell the block device(s) that the sectors can be discarded */ 1820 /* Tell the block device(s) that the sectors can be discarded */
1821 ret = btrfs_map_block(&root->fs_info->mapping_tree, REQ_DISCARD, 1821 ret = btrfs_map_block(root->fs_info, REQ_DISCARD,
1822 bytenr, &num_bytes, &bbio, 0); 1822 bytenr, &num_bytes, &bbio, 0);
1823 /* Error condition is -ENOMEM */ 1823 /* Error condition is -ENOMEM */
1824 if (!ret) { 1824 if (!ret) {
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index e0b7138909f0..62ec6e45f705 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1917,12 +1917,12 @@ static void repair_io_failure_callback(struct bio *bio, int err)
1917 * the standard behavior is to write all copies in a raid setup. here we only 1917 * the standard behavior is to write all copies in a raid setup. here we only
1918 * want to write the one bad copy. so we do the mapping for ourselves and issue 1918 * want to write the one bad copy. so we do the mapping for ourselves and issue
1919 * submit_bio directly. 1919 * submit_bio directly.
1920 * to avoid any synchonization issues, wait for the data after writing, which 1920 * to avoid any synchronization issues, wait for the data after writing, which
1921 * actually prevents the read that triggered the error from finishing. 1921 * actually prevents the read that triggered the error from finishing.
1922 * currently, there can be no more than two copies of every data bit. thus, 1922 * currently, there can be no more than two copies of every data bit. thus,
1923 * exactly one rewrite is required. 1923 * exactly one rewrite is required.
1924 */ 1924 */
1925int repair_io_failure(struct btrfs_mapping_tree *map_tree, u64 start, 1925int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
1926 u64 length, u64 logical, struct page *page, 1926 u64 length, u64 logical, struct page *page,
1927 int mirror_num) 1927 int mirror_num)
1928{ 1928{
@@ -1944,7 +1944,7 @@ int repair_io_failure(struct btrfs_mapping_tree *map_tree, u64 start,
1944 bio->bi_size = 0; 1944 bio->bi_size = 0;
1945 map_length = length; 1945 map_length = length;
1946 1946
1947 ret = btrfs_map_block(map_tree, WRITE, logical, 1947 ret = btrfs_map_block(fs_info, WRITE, logical,
1948 &map_length, &bbio, mirror_num); 1948 &map_length, &bbio, mirror_num);
1949 if (ret) { 1949 if (ret) {
1950 bio_put(bio); 1950 bio_put(bio);
@@ -1982,14 +1982,13 @@ int repair_io_failure(struct btrfs_mapping_tree *map_tree, u64 start,
1982int repair_eb_io_failure(struct btrfs_root *root, struct extent_buffer *eb, 1982int repair_eb_io_failure(struct btrfs_root *root, struct extent_buffer *eb,
1983 int mirror_num) 1983 int mirror_num)
1984{ 1984{
1985 struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree;
1986 u64 start = eb->start; 1985 u64 start = eb->start;
1987 unsigned long i, num_pages = num_extent_pages(eb->start, eb->len); 1986 unsigned long i, num_pages = num_extent_pages(eb->start, eb->len);
1988 int ret = 0; 1987 int ret = 0;
1989 1988
1990 for (i = 0; i < num_pages; i++) { 1989 for (i = 0; i < num_pages; i++) {
1991 struct page *p = extent_buffer_page(eb, i); 1990 struct page *p = extent_buffer_page(eb, i);
1992 ret = repair_io_failure(map_tree, start, PAGE_CACHE_SIZE, 1991 ret = repair_io_failure(root->fs_info, start, PAGE_CACHE_SIZE,
1993 start, p, mirror_num); 1992 start, p, mirror_num);
1994 if (ret) 1993 if (ret)
1995 break; 1994 break;
@@ -2008,7 +2007,7 @@ static int clean_io_failure(u64 start, struct page *page)
2008 u64 private; 2007 u64 private;
2009 u64 private_failure; 2008 u64 private_failure;
2010 struct io_failure_record *failrec; 2009 struct io_failure_record *failrec;
2011 struct btrfs_mapping_tree *map_tree; 2010 struct btrfs_fs_info *fs_info;
2012 struct extent_state *state; 2011 struct extent_state *state;
2013 int num_copies; 2012 int num_copies;
2014 int did_repair = 0; 2013 int did_repair = 0;
@@ -2044,11 +2043,11 @@ static int clean_io_failure(u64 start, struct page *page)
2044 spin_unlock(&BTRFS_I(inode)->io_tree.lock); 2043 spin_unlock(&BTRFS_I(inode)->io_tree.lock);
2045 2044
2046 if (state && state->start == failrec->start) { 2045 if (state && state->start == failrec->start) {
2047 num_copies = btrfs_num_copies(BTRFS_I(inode)->root->fs_info, 2046 fs_info = BTRFS_I(inode)->root->fs_info;
2048 failrec->logical, failrec->len); 2047 num_copies = btrfs_num_copies(fs_info, failrec->logical,
2048 failrec->len);
2049 if (num_copies > 1) { 2049 if (num_copies > 1) {
2050 map_tree = &BTRFS_I(inode)->root->fs_info->mapping_tree; 2050 ret = repair_io_failure(fs_info, start, failrec->len,
2051 ret = repair_io_failure(map_tree, start, failrec->len,
2052 failrec->logical, page, 2051 failrec->logical, page,
2053 failrec->failed_mirror); 2052 failrec->failed_mirror);
2054 did_repair = !ret; 2053 did_repair = !ret;
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 711d12b80028..2eacfabd3263 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -337,9 +337,9 @@ struct bio *
337btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs, 337btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs,
338 gfp_t gfp_flags); 338 gfp_t gfp_flags);
339 339
340struct btrfs_mapping_tree; 340struct btrfs_fs_info;
341 341
342int repair_io_failure(struct btrfs_mapping_tree *map_tree, u64 start, 342int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
343 u64 length, u64 logical, struct page *page, 343 u64 length, u64 logical, struct page *page,
344 int mirror_num); 344 int mirror_num);
345int end_extent_writepage(struct page *page, int err, u64 start, u64 end); 345int end_extent_writepage(struct page *page, int err, u64 start, u64 end);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index aabf747d056e..5d1675a8c9e2 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1549,7 +1549,6 @@ int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
1549 unsigned long bio_flags) 1549 unsigned long bio_flags)
1550{ 1550{
1551 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root; 1551 struct btrfs_root *root = BTRFS_I(page->mapping->host)->root;
1552 struct btrfs_mapping_tree *map_tree;
1553 u64 logical = (u64)bio->bi_sector << 9; 1552 u64 logical = (u64)bio->bi_sector << 9;
1554 u64 length = 0; 1553 u64 length = 0;
1555 u64 map_length; 1554 u64 map_length;
@@ -1559,11 +1558,10 @@ int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
1559 return 0; 1558 return 0;
1560 1559
1561 length = bio->bi_size; 1560 length = bio->bi_size;
1562 map_tree = &root->fs_info->mapping_tree;
1563 map_length = length; 1561 map_length = length;
1564 ret = btrfs_map_block(map_tree, READ, logical, 1562 ret = btrfs_map_block(root->fs_info, READ, logical,
1565 &map_length, NULL, 0); 1563 &map_length, NULL, 0);
1566 /* Will always return 0 or 1 with map_multi == NULL */ 1564 /* Will always return 0 with map_multi == NULL */
1567 BUG_ON(ret < 0); 1565 BUG_ON(ret < 0);
1568 if (map_length < length + size) 1566 if (map_length < length + size)
1569 return 1; 1567 return 1;
@@ -6364,7 +6362,6 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip,
6364{ 6362{
6365 struct inode *inode = dip->inode; 6363 struct inode *inode = dip->inode;
6366 struct btrfs_root *root = BTRFS_I(inode)->root; 6364 struct btrfs_root *root = BTRFS_I(inode)->root;
6367 struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree;
6368 struct bio *bio; 6365 struct bio *bio;
6369 struct bio *orig_bio = dip->orig_bio; 6366 struct bio *orig_bio = dip->orig_bio;
6370 struct bio_vec *bvec = orig_bio->bi_io_vec; 6367 struct bio_vec *bvec = orig_bio->bi_io_vec;
@@ -6377,7 +6374,7 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip,
6377 int async_submit = 0; 6374 int async_submit = 0;
6378 6375
6379 map_length = orig_bio->bi_size; 6376 map_length = orig_bio->bi_size;
6380 ret = btrfs_map_block(map_tree, READ, start_sector << 9, 6377 ret = btrfs_map_block(root->fs_info, READ, start_sector << 9,
6381 &map_length, NULL, 0); 6378 &map_length, NULL, 0);
6382 if (ret) { 6379 if (ret) {
6383 bio_put(orig_bio); 6380 bio_put(orig_bio);
@@ -6431,7 +6428,8 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip,
6431 bio->bi_end_io = btrfs_end_dio_bio; 6428 bio->bi_end_io = btrfs_end_dio_bio;
6432 6429
6433 map_length = orig_bio->bi_size; 6430 map_length = orig_bio->bi_size;
6434 ret = btrfs_map_block(map_tree, READ, start_sector << 9, 6431 ret = btrfs_map_block(root->fs_info, READ,
6432 start_sector << 9,
6435 &map_length, NULL, 0); 6433 &map_length, NULL, 0);
6436 if (ret) { 6434 if (ret) {
6437 bio_put(bio); 6435 bio_put(bio);
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index a955669519a2..0ddc5659f946 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -323,7 +323,6 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
323 struct reada_extent *re = NULL; 323 struct reada_extent *re = NULL;
324 struct reada_extent *re_exist = NULL; 324 struct reada_extent *re_exist = NULL;
325 struct btrfs_fs_info *fs_info = root->fs_info; 325 struct btrfs_fs_info *fs_info = root->fs_info;
326 struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree;
327 struct btrfs_bio *bbio = NULL; 326 struct btrfs_bio *bbio = NULL;
328 struct btrfs_device *dev; 327 struct btrfs_device *dev;
329 struct btrfs_device *prev_dev; 328 struct btrfs_device *prev_dev;
@@ -358,7 +357,7 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root,
358 * map block 357 * map block
359 */ 358 */
360 length = blocksize; 359 length = blocksize;
361 ret = btrfs_map_block(map_tree, REQ_WRITE, logical, &length, &bbio, 0); 360 ret = btrfs_map_block(fs_info, REQ_WRITE, logical, &length, &bbio, 0);
362 if (ret || !bbio || length < blocksize) 361 if (ret || !bbio || length < blocksize)
363 goto error; 362 goto error;
364 363
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index a67b1a17a009..894bb2732fcc 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -152,7 +152,7 @@ static void scrub_pending_trans_workers_inc(struct scrub_ctx *sctx);
152static void scrub_pending_trans_workers_dec(struct scrub_ctx *sctx); 152static void scrub_pending_trans_workers_dec(struct scrub_ctx *sctx);
153static int scrub_handle_errored_block(struct scrub_block *sblock_to_check); 153static int scrub_handle_errored_block(struct scrub_block *sblock_to_check);
154static int scrub_setup_recheck_block(struct scrub_ctx *sctx, 154static int scrub_setup_recheck_block(struct scrub_ctx *sctx,
155 struct btrfs_mapping_tree *map_tree, 155 struct btrfs_fs_info *fs_info,
156 u64 length, u64 logical, 156 u64 length, u64 logical,
157 struct scrub_block *sblock); 157 struct scrub_block *sblock);
158static void scrub_recheck_block(struct btrfs_fs_info *fs_info, 158static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
@@ -523,7 +523,7 @@ static int scrub_fixup_readpage(u64 inum, u64 offset, u64 root, void *ctx)
523 } 523 }
524 524
525 if (PageUptodate(page)) { 525 if (PageUptodate(page)) {
526 struct btrfs_mapping_tree *map_tree; 526 struct btrfs_fs_info *fs_info;
527 if (PageDirty(page)) { 527 if (PageDirty(page)) {
528 /* 528 /*
529 * we need to write the data to the defect sector. the 529 * we need to write the data to the defect sector. the
@@ -544,8 +544,8 @@ static int scrub_fixup_readpage(u64 inum, u64 offset, u64 root, void *ctx)
544 ret = -EIO; 544 ret = -EIO;
545 goto out; 545 goto out;
546 } 546 }
547 map_tree = &BTRFS_I(inode)->root->fs_info->mapping_tree; 547 fs_info = BTRFS_I(inode)->root->fs_info;
548 ret = repair_io_failure(map_tree, offset, PAGE_SIZE, 548 ret = repair_io_failure(fs_info, offset, PAGE_SIZE,
549 fixup->logical, page, 549 fixup->logical, page,
550 fixup->mirror_num); 550 fixup->mirror_num);
551 unlock_page(page); 551 unlock_page(page);
@@ -754,7 +754,7 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
754 } 754 }
755 755
756 /* setup the context, map the logical blocks and alloc the pages */ 756 /* setup the context, map the logical blocks and alloc the pages */
757 ret = scrub_setup_recheck_block(sctx, &fs_info->mapping_tree, length, 757 ret = scrub_setup_recheck_block(sctx, fs_info, length,
758 logical, sblocks_for_recheck); 758 logical, sblocks_for_recheck);
759 if (ret) { 759 if (ret) {
760 spin_lock(&sctx->stat_lock); 760 spin_lock(&sctx->stat_lock);
@@ -1012,7 +1012,7 @@ out:
1012} 1012}
1013 1013
1014static int scrub_setup_recheck_block(struct scrub_ctx *sctx, 1014static int scrub_setup_recheck_block(struct scrub_ctx *sctx,
1015 struct btrfs_mapping_tree *map_tree, 1015 struct btrfs_fs_info *fs_info,
1016 u64 length, u64 logical, 1016 u64 length, u64 logical,
1017 struct scrub_block *sblocks_for_recheck) 1017 struct scrub_block *sblocks_for_recheck)
1018{ 1018{
@@ -1036,7 +1036,7 @@ static int scrub_setup_recheck_block(struct scrub_ctx *sctx,
1036 * with a length of PAGE_SIZE, each returned stripe 1036 * with a length of PAGE_SIZE, each returned stripe
1037 * represents one mirror 1037 * represents one mirror
1038 */ 1038 */
1039 ret = btrfs_map_block(map_tree, WRITE, logical, &mapped_length, 1039 ret = btrfs_map_block(fs_info, WRITE, logical, &mapped_length,
1040 &bbio, 0); 1040 &bbio, 0);
1041 if (ret || !bbio || mapped_length < sublen) { 1041 if (ret || !bbio || mapped_length < sublen) {
1042 kfree(bbio); 1042 kfree(bbio);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 5612767b910e..96bb2e4446aa 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3826,13 +3826,14 @@ static int find_live_mirror(struct map_lookup *map, int first, int num,
3826 return optimal; 3826 return optimal;
3827} 3827}
3828 3828
3829static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, 3829static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
3830 u64 logical, u64 *length, 3830 u64 logical, u64 *length,
3831 struct btrfs_bio **bbio_ret, 3831 struct btrfs_bio **bbio_ret,
3832 int mirror_num) 3832 int mirror_num)
3833{ 3833{
3834 struct extent_map *em; 3834 struct extent_map *em;
3835 struct map_lookup *map; 3835 struct map_lookup *map;
3836 struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree;
3836 struct extent_map_tree *em_tree = &map_tree->map_tree; 3837 struct extent_map_tree *em_tree = &map_tree->map_tree;
3837 u64 offset; 3838 u64 offset;
3838 u64 stripe_offset; 3839 u64 stripe_offset;
@@ -4061,11 +4062,11 @@ out:
4061 return ret; 4062 return ret;
4062} 4063}
4063 4064
4064int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, 4065int btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
4065 u64 logical, u64 *length, 4066 u64 logical, u64 *length,
4066 struct btrfs_bio **bbio_ret, int mirror_num) 4067 struct btrfs_bio **bbio_ret, int mirror_num)
4067{ 4068{
4068 return __btrfs_map_block(map_tree, rw, logical, length, bbio_ret, 4069 return __btrfs_map_block(fs_info, rw, logical, length, bbio_ret,
4069 mirror_num); 4070 mirror_num);
4070} 4071}
4071 4072
@@ -4394,7 +4395,6 @@ static void bbio_error(struct btrfs_bio *bbio, struct bio *bio, u64 logical)
4394int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio, 4395int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
4395 int mirror_num, int async_submit) 4396 int mirror_num, int async_submit)
4396{ 4397{
4397 struct btrfs_mapping_tree *map_tree;
4398 struct btrfs_device *dev; 4398 struct btrfs_device *dev;
4399 struct bio *first_bio = bio; 4399 struct bio *first_bio = bio;
4400 u64 logical = (u64)bio->bi_sector << 9; 4400 u64 logical = (u64)bio->bi_sector << 9;
@@ -4406,10 +4406,9 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
4406 struct btrfs_bio *bbio = NULL; 4406 struct btrfs_bio *bbio = NULL;
4407 4407
4408 length = bio->bi_size; 4408 length = bio->bi_size;
4409 map_tree = &root->fs_info->mapping_tree;
4410 map_length = length; 4409 map_length = length;
4411 4410
4412 ret = btrfs_map_block(map_tree, rw, logical, &map_length, &bbio, 4411 ret = btrfs_map_block(root->fs_info, rw, logical, &map_length, &bbio,
4413 mirror_num); 4412 mirror_num);
4414 if (ret) /* -ENOMEM */ 4413 if (ret) /* -ENOMEM */
4415 return ret; 4414 return ret;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 35ea4424963b..ad5566d4f2c8 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -248,7 +248,7 @@ int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
248 struct btrfs_device *device, 248 struct btrfs_device *device,
249 u64 chunk_tree, u64 chunk_objectid, 249 u64 chunk_tree, u64 chunk_objectid,
250 u64 chunk_offset, u64 start, u64 num_bytes); 250 u64 chunk_offset, u64 start, u64 num_bytes);
251int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, 251int btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
252 u64 logical, u64 *length, 252 u64 logical, u64 *length,
253 struct btrfs_bio **bbio_ret, int mirror_num); 253 struct btrfs_bio **bbio_ret, int mirror_num);
254int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree, 254int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,