aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-07-20 09:29:37 -0400
committerJens Axboe <axboe@fb.com>2015-07-29 10:55:15 -0400
commit4246a0b63bd8f56a1469b12eafeb875b1041a451 (patch)
tree3281bb158d658ef7f208ad380c0ecee600a5ab5e /fs/btrfs
parent0034af036554c39eefd14d835a8ec3496ac46712 (diff)
block: add a bi_error field to struct bio
Currently we have two different ways to signal an I/O error on a BIO: (1) by clearing the BIO_UPTODATE flag (2) by returning a Linux errno value to the bi_end_io callback The first one has the drawback of only communicating a single possible error (-EIO), and the second one has the drawback of not beeing persistent when bios are queued up, and are not passed along from child to parent bio in the ever more popular chaining scenario. Having both mechanisms available has the additional drawback of utterly confusing driver authors and introducing bugs where various I/O submitters only deal with one of them, and the others have to add boilerplate code to deal with both kinds of error returns. So add a new bi_error field to store an errno value directly in struct bio and remove the existing mechanisms to clean all this up. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: NeilBrown <neilb@suse.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/check-integrity.c10
-rw-r--r--fs/btrfs/compression.c24
-rw-r--r--fs/btrfs/disk-io.c35
-rw-r--r--fs/btrfs/extent_io.c30
-rw-r--r--fs/btrfs/inode.c50
-rw-r--r--fs/btrfs/raid56.c62
-rw-r--r--fs/btrfs/scrub.c22
-rw-r--r--fs/btrfs/volumes.c23
8 files changed, 126 insertions, 130 deletions
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index ce7dec88f4b8..541fbfaed276 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -343,7 +343,7 @@ static int btrfsic_process_written_superblock(
343 struct btrfsic_state *state, 343 struct btrfsic_state *state,
344 struct btrfsic_block *const block, 344 struct btrfsic_block *const block,
345 struct btrfs_super_block *const super_hdr); 345 struct btrfs_super_block *const super_hdr);
346static void btrfsic_bio_end_io(struct bio *bp, int bio_error_status); 346static void btrfsic_bio_end_io(struct bio *bp);
347static void btrfsic_bh_end_io(struct buffer_head *bh, int uptodate); 347static void btrfsic_bh_end_io(struct buffer_head *bh, int uptodate);
348static int btrfsic_is_block_ref_by_superblock(const struct btrfsic_state *state, 348static int btrfsic_is_block_ref_by_superblock(const struct btrfsic_state *state,
349 const struct btrfsic_block *block, 349 const struct btrfsic_block *block,
@@ -2207,7 +2207,7 @@ continue_loop:
2207 goto again; 2207 goto again;
2208} 2208}
2209 2209
2210static void btrfsic_bio_end_io(struct bio *bp, int bio_error_status) 2210static void btrfsic_bio_end_io(struct bio *bp)
2211{ 2211{
2212 struct btrfsic_block *block = (struct btrfsic_block *)bp->bi_private; 2212 struct btrfsic_block *block = (struct btrfsic_block *)bp->bi_private;
2213 int iodone_w_error; 2213 int iodone_w_error;
@@ -2215,7 +2215,7 @@ static void btrfsic_bio_end_io(struct bio *bp, int bio_error_status)
2215 /* mutex is not held! This is not save if IO is not yet completed 2215 /* mutex is not held! This is not save if IO is not yet completed
2216 * on umount */ 2216 * on umount */
2217 iodone_w_error = 0; 2217 iodone_w_error = 0;
2218 if (bio_error_status) 2218 if (bp->bi_error)
2219 iodone_w_error = 1; 2219 iodone_w_error = 1;
2220 2220
2221 BUG_ON(NULL == block); 2221 BUG_ON(NULL == block);
@@ -2230,7 +2230,7 @@ static void btrfsic_bio_end_io(struct bio *bp, int bio_error_status)
2230 BTRFSIC_PRINT_MASK_END_IO_BIO_BH)) 2230 BTRFSIC_PRINT_MASK_END_IO_BIO_BH))
2231 printk(KERN_INFO 2231 printk(KERN_INFO
2232 "bio_end_io(err=%d) for %c @%llu (%s/%llu/%d)\n", 2232 "bio_end_io(err=%d) for %c @%llu (%s/%llu/%d)\n",
2233 bio_error_status, 2233 bp->bi_error,
2234 btrfsic_get_block_type(dev_state->state, block), 2234 btrfsic_get_block_type(dev_state->state, block),
2235 block->logical_bytenr, dev_state->name, 2235 block->logical_bytenr, dev_state->name,
2236 block->dev_bytenr, block->mirror_num); 2236 block->dev_bytenr, block->mirror_num);
@@ -2252,7 +2252,7 @@ static void btrfsic_bio_end_io(struct bio *bp, int bio_error_status)
2252 block = next_block; 2252 block = next_block;
2253 } while (NULL != block); 2253 } while (NULL != block);
2254 2254
2255 bp->bi_end_io(bp, bio_error_status); 2255 bp->bi_end_io(bp);
2256} 2256}
2257 2257
2258static void btrfsic_bh_end_io(struct buffer_head *bh, int uptodate) 2258static void btrfsic_bh_end_io(struct buffer_head *bh, int uptodate)
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index ce62324c78e7..302266ec2cdb 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -152,7 +152,7 @@ fail:
152 * The compressed pages are freed here, and it must be run 152 * The compressed pages are freed here, and it must be run
153 * in process context 153 * in process context
154 */ 154 */
155static void end_compressed_bio_read(struct bio *bio, int err) 155static void end_compressed_bio_read(struct bio *bio)
156{ 156{
157 struct compressed_bio *cb = bio->bi_private; 157 struct compressed_bio *cb = bio->bi_private;
158 struct inode *inode; 158 struct inode *inode;
@@ -160,7 +160,7 @@ static void end_compressed_bio_read(struct bio *bio, int err)
160 unsigned long index; 160 unsigned long index;
161 int ret; 161 int ret;
162 162
163 if (err) 163 if (bio->bi_error)
164 cb->errors = 1; 164 cb->errors = 1;
165 165
166 /* if there are more bios still pending for this compressed 166 /* if there are more bios still pending for this compressed
@@ -210,7 +210,7 @@ csum_failed:
210 bio_for_each_segment_all(bvec, cb->orig_bio, i) 210 bio_for_each_segment_all(bvec, cb->orig_bio, i)
211 SetPageChecked(bvec->bv_page); 211 SetPageChecked(bvec->bv_page);
212 212
213 bio_endio(cb->orig_bio, 0); 213 bio_endio(cb->orig_bio);
214 } 214 }
215 215
216 /* finally free the cb struct */ 216 /* finally free the cb struct */
@@ -266,7 +266,7 @@ static noinline void end_compressed_writeback(struct inode *inode,
266 * This also calls the writeback end hooks for the file pages so that 266 * This also calls the writeback end hooks for the file pages so that
267 * metadata and checksums can be updated in the file. 267 * metadata and checksums can be updated in the file.
268 */ 268 */
269static void end_compressed_bio_write(struct bio *bio, int err) 269static void end_compressed_bio_write(struct bio *bio)
270{ 270{
271 struct extent_io_tree *tree; 271 struct extent_io_tree *tree;
272 struct compressed_bio *cb = bio->bi_private; 272 struct compressed_bio *cb = bio->bi_private;
@@ -274,7 +274,7 @@ static void end_compressed_bio_write(struct bio *bio, int err)
274 struct page *page; 274 struct page *page;
275 unsigned long index; 275 unsigned long index;
276 276
277 if (err) 277 if (bio->bi_error)
278 cb->errors = 1; 278 cb->errors = 1;
279 279
280 /* if there are more bios still pending for this compressed 280 /* if there are more bios still pending for this compressed
@@ -293,7 +293,7 @@ static void end_compressed_bio_write(struct bio *bio, int err)
293 cb->start, 293 cb->start,
294 cb->start + cb->len - 1, 294 cb->start + cb->len - 1,
295 NULL, 295 NULL,
296 err ? 0 : 1); 296 bio->bi_error ? 0 : 1);
297 cb->compressed_pages[0]->mapping = NULL; 297 cb->compressed_pages[0]->mapping = NULL;
298 298
299 end_compressed_writeback(inode, cb); 299 end_compressed_writeback(inode, cb);
@@ -697,8 +697,10 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
697 697
698 ret = btrfs_map_bio(root, READ, comp_bio, 698 ret = btrfs_map_bio(root, READ, comp_bio,
699 mirror_num, 0); 699 mirror_num, 0);
700 if (ret) 700 if (ret) {
701 bio_endio(comp_bio, ret); 701 bio->bi_error = ret;
702 bio_endio(comp_bio);
703 }
702 704
703 bio_put(comp_bio); 705 bio_put(comp_bio);
704 706
@@ -724,8 +726,10 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
724 } 726 }
725 727
726 ret = btrfs_map_bio(root, READ, comp_bio, mirror_num, 0); 728 ret = btrfs_map_bio(root, READ, comp_bio, mirror_num, 0);
727 if (ret) 729 if (ret) {
728 bio_endio(comp_bio, ret); 730 bio->bi_error = ret;
731 bio_endio(comp_bio);
732 }
729 733
730 bio_put(comp_bio); 734 bio_put(comp_bio);
731 return 0; 735 return 0;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index a9aadb2ad525..a8c0de888a9d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -703,7 +703,7 @@ static int btree_io_failed_hook(struct page *page, int failed_mirror)
703 return -EIO; /* we fixed nothing */ 703 return -EIO; /* we fixed nothing */
704} 704}
705 705
706static void end_workqueue_bio(struct bio *bio, int err) 706static void end_workqueue_bio(struct bio *bio)
707{ 707{
708 struct btrfs_end_io_wq *end_io_wq = bio->bi_private; 708 struct btrfs_end_io_wq *end_io_wq = bio->bi_private;
709 struct btrfs_fs_info *fs_info; 709 struct btrfs_fs_info *fs_info;
@@ -711,7 +711,7 @@ static void end_workqueue_bio(struct bio *bio, int err)
711 btrfs_work_func_t func; 711 btrfs_work_func_t func;
712 712
713 fs_info = end_io_wq->info; 713 fs_info = end_io_wq->info;
714 end_io_wq->error = err; 714 end_io_wq->error = bio->bi_error;
715 715
716 if (bio->bi_rw & REQ_WRITE) { 716 if (bio->bi_rw & REQ_WRITE) {
717 if (end_io_wq->metadata == BTRFS_WQ_ENDIO_METADATA) { 717 if (end_io_wq->metadata == BTRFS_WQ_ENDIO_METADATA) {
@@ -808,7 +808,8 @@ static void run_one_async_done(struct btrfs_work *work)
808 808
809 /* If an error occured we just want to clean up the bio and move on */ 809 /* If an error occured we just want to clean up the bio and move on */
810 if (async->error) { 810 if (async->error) {
811 bio_endio(async->bio, async->error); 811 async->bio->bi_error = async->error;
812 bio_endio(async->bio);
812 return; 813 return;
813 } 814 }
814 815
@@ -908,8 +909,10 @@ static int __btree_submit_bio_done(struct inode *inode, int rw, struct bio *bio,
908 * submission context. Just jump into btrfs_map_bio 909 * submission context. Just jump into btrfs_map_bio
909 */ 910 */
910 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, mirror_num, 1); 911 ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio, mirror_num, 1);
911 if (ret) 912 if (ret) {
912 bio_endio(bio, ret); 913 bio->bi_error = ret;
914 bio_endio(bio);
915 }
913 return ret; 916 return ret;
914} 917}
915 918
@@ -960,10 +963,13 @@ static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
960 __btree_submit_bio_done); 963 __btree_submit_bio_done);
961 } 964 }
962 965
963 if (ret) { 966 if (ret)
967 goto out_w_error;
968 return 0;
969
964out_w_error: 970out_w_error:
965 bio_endio(bio, ret); 971 bio->bi_error = ret;
966 } 972 bio_endio(bio);
967 return ret; 973 return ret;
968} 974}
969 975
@@ -1735,16 +1741,15 @@ static void end_workqueue_fn(struct btrfs_work *work)
1735{ 1741{
1736 struct bio *bio; 1742 struct bio *bio;
1737 struct btrfs_end_io_wq *end_io_wq; 1743 struct btrfs_end_io_wq *end_io_wq;
1738 int error;
1739 1744
1740 end_io_wq = container_of(work, struct btrfs_end_io_wq, work); 1745 end_io_wq = container_of(work, struct btrfs_end_io_wq, work);
1741 bio = end_io_wq->bio; 1746 bio = end_io_wq->bio;
1742 1747
1743 error = end_io_wq->error; 1748 bio->bi_error = end_io_wq->error;
1744 bio->bi_private = end_io_wq->private; 1749 bio->bi_private = end_io_wq->private;
1745 bio->bi_end_io = end_io_wq->end_io; 1750 bio->bi_end_io = end_io_wq->end_io;
1746 kmem_cache_free(btrfs_end_io_wq_cache, end_io_wq); 1751 kmem_cache_free(btrfs_end_io_wq_cache, end_io_wq);
1747 bio_endio(bio, error); 1752 bio_endio(bio);
1748} 1753}
1749 1754
1750static int cleaner_kthread(void *arg) 1755static int cleaner_kthread(void *arg)
@@ -3323,10 +3328,8 @@ static int write_dev_supers(struct btrfs_device *device,
3323 * endio for the write_dev_flush, this will wake anyone waiting 3328 * endio for the write_dev_flush, this will wake anyone waiting
3324 * for the barrier when it is done 3329 * for the barrier when it is done
3325 */ 3330 */
3326static void btrfs_end_empty_barrier(struct bio *bio, int err) 3331static void btrfs_end_empty_barrier(struct bio *bio)
3327{ 3332{
3328 if (err)
3329 clear_bit(BIO_UPTODATE, &bio->bi_flags);
3330 if (bio->bi_private) 3333 if (bio->bi_private)
3331 complete(bio->bi_private); 3334 complete(bio->bi_private);
3332 bio_put(bio); 3335 bio_put(bio);
@@ -3354,8 +3357,8 @@ static int write_dev_flush(struct btrfs_device *device, int wait)
3354 3357
3355 wait_for_completion(&device->flush_wait); 3358 wait_for_completion(&device->flush_wait);
3356 3359
3357 if (!bio_flagged(bio, BIO_UPTODATE)) { 3360 if (bio->bi_error) {
3358 ret = -EIO; 3361 ret = bio->bi_error;
3359 btrfs_dev_stat_inc_and_print(device, 3362 btrfs_dev_stat_inc_and_print(device,
3360 BTRFS_DEV_STAT_FLUSH_ERRS); 3363 BTRFS_DEV_STAT_FLUSH_ERRS);
3361 } 3364 }
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 02d05817cbdf..c22f175ed024 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2486,7 +2486,7 @@ int end_extent_writepage(struct page *page, int err, u64 start, u64 end)
2486 * Scheduling is not allowed, so the extent state tree is expected 2486 * Scheduling is not allowed, so the extent state tree is expected
2487 * to have one and only one object corresponding to this IO. 2487 * to have one and only one object corresponding to this IO.
2488 */ 2488 */
2489static void end_bio_extent_writepage(struct bio *bio, int err) 2489static void end_bio_extent_writepage(struct bio *bio)
2490{ 2490{
2491 struct bio_vec *bvec; 2491 struct bio_vec *bvec;
2492 u64 start; 2492 u64 start;
@@ -2516,7 +2516,7 @@ static void end_bio_extent_writepage(struct bio *bio, int err)
2516 start = page_offset(page); 2516 start = page_offset(page);
2517 end = start + bvec->bv_offset + bvec->bv_len - 1; 2517 end = start + bvec->bv_offset + bvec->bv_len - 1;
2518 2518
2519 if (end_extent_writepage(page, err, start, end)) 2519 if (end_extent_writepage(page, bio->bi_error, start, end))
2520 continue; 2520 continue;
2521 2521
2522 end_page_writeback(page); 2522 end_page_writeback(page);
@@ -2548,10 +2548,10 @@ endio_readpage_release_extent(struct extent_io_tree *tree, u64 start, u64 len,
2548 * Scheduling is not allowed, so the extent state tree is expected 2548 * Scheduling is not allowed, so the extent state tree is expected
2549 * to have one and only one object corresponding to this IO. 2549 * to have one and only one object corresponding to this IO.
2550 */ 2550 */
2551static void end_bio_extent_readpage(struct bio *bio, int err) 2551static void end_bio_extent_readpage(struct bio *bio)
2552{ 2552{
2553 struct bio_vec *bvec; 2553 struct bio_vec *bvec;
2554 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 2554 int uptodate = !bio->bi_error;
2555 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); 2555 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio);
2556 struct extent_io_tree *tree; 2556 struct extent_io_tree *tree;
2557 u64 offset = 0; 2557 u64 offset = 0;
@@ -2564,16 +2564,13 @@ static void end_bio_extent_readpage(struct bio *bio, int err)
2564 int ret; 2564 int ret;
2565 int i; 2565 int i;
2566 2566
2567 if (err)
2568 uptodate = 0;
2569
2570 bio_for_each_segment_all(bvec, bio, i) { 2567 bio_for_each_segment_all(bvec, bio, i) {
2571 struct page *page = bvec->bv_page; 2568 struct page *page = bvec->bv_page;
2572 struct inode *inode = page->mapping->host; 2569 struct inode *inode = page->mapping->host;
2573 2570
2574 pr_debug("end_bio_extent_readpage: bi_sector=%llu, err=%d, " 2571 pr_debug("end_bio_extent_readpage: bi_sector=%llu, err=%d, "
2575 "mirror=%u\n", (u64)bio->bi_iter.bi_sector, err, 2572 "mirror=%u\n", (u64)bio->bi_iter.bi_sector,
2576 io_bio->mirror_num); 2573 bio->bi_error, io_bio->mirror_num);
2577 tree = &BTRFS_I(inode)->io_tree; 2574 tree = &BTRFS_I(inode)->io_tree;
2578 2575
2579 /* We always issue full-page reads, but if some block 2576 /* We always issue full-page reads, but if some block
@@ -2614,8 +2611,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err)
2614 2611
2615 if (tree->ops && tree->ops->readpage_io_failed_hook) { 2612 if (tree->ops && tree->ops->readpage_io_failed_hook) {
2616 ret = tree->ops->readpage_io_failed_hook(page, mirror); 2613 ret = tree->ops->readpage_io_failed_hook(page, mirror);
2617 if (!ret && !err && 2614 if (!ret && !bio->bi_error)
2618 test_bit(BIO_UPTODATE, &bio->bi_flags))
2619 uptodate = 1; 2615 uptodate = 1;
2620 } else { 2616 } else {
2621 /* 2617 /*
@@ -2631,10 +2627,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err)
2631 ret = bio_readpage_error(bio, offset, page, start, end, 2627 ret = bio_readpage_error(bio, offset, page, start, end,
2632 mirror); 2628 mirror);
2633 if (ret == 0) { 2629 if (ret == 0) {
2634 uptodate = 2630 uptodate = !bio->bi_error;
2635 test_bit(BIO_UPTODATE, &bio->bi_flags);
2636 if (err)
2637 uptodate = 0;
2638 offset += len; 2631 offset += len;
2639 continue; 2632 continue;
2640 } 2633 }
@@ -2684,7 +2677,7 @@ readpage_ok:
2684 endio_readpage_release_extent(tree, extent_start, extent_len, 2677 endio_readpage_release_extent(tree, extent_start, extent_len,
2685 uptodate); 2678 uptodate);
2686 if (io_bio->end_io) 2679 if (io_bio->end_io)
2687 io_bio->end_io(io_bio, err); 2680 io_bio->end_io(io_bio, bio->bi_error);
2688 bio_put(bio); 2681 bio_put(bio);
2689} 2682}
2690 2683
@@ -3696,7 +3689,7 @@ static void set_btree_ioerr(struct page *page)
3696 } 3689 }
3697} 3690}
3698 3691
3699static void end_bio_extent_buffer_writepage(struct bio *bio, int err) 3692static void end_bio_extent_buffer_writepage(struct bio *bio)
3700{ 3693{
3701 struct bio_vec *bvec; 3694 struct bio_vec *bvec;
3702 struct extent_buffer *eb; 3695 struct extent_buffer *eb;
@@ -3709,7 +3702,8 @@ static void end_bio_extent_buffer_writepage(struct bio *bio, int err)
3709 BUG_ON(!eb); 3702 BUG_ON(!eb);
3710 done = atomic_dec_and_test(&eb->io_pages); 3703 done = atomic_dec_and_test(&eb->io_pages);
3711 3704
3712 if (err || test_bit(EXTENT_BUFFER_WRITE_ERR, &eb->bflags)) { 3705 if (bio->bi_error ||
3706 test_bit(EXTENT_BUFFER_WRITE_ERR, &eb->bflags)) {
3713 ClearPageUptodate(page); 3707 ClearPageUptodate(page);
3714 set_btree_ioerr(page); 3708 set_btree_ioerr(page);
3715 } 3709 }
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index b33c0cf02668..6b8becfe2057 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1845,8 +1845,10 @@ static int __btrfs_submit_bio_done(struct inode *inode, int rw, struct bio *bio,
1845 int ret; 1845 int ret;
1846 1846
1847 ret = btrfs_map_bio(root, rw, bio, mirror_num, 1); 1847 ret = btrfs_map_bio(root, rw, bio, mirror_num, 1);
1848 if (ret) 1848 if (ret) {
1849 bio_endio(bio, ret); 1849 bio->bi_error = ret;
1850 bio_endio(bio);
1851 }
1850 return ret; 1852 return ret;
1851} 1853}
1852 1854
@@ -1906,8 +1908,10 @@ mapit:
1906 ret = btrfs_map_bio(root, rw, bio, mirror_num, 0); 1908 ret = btrfs_map_bio(root, rw, bio, mirror_num, 0);
1907 1909
1908out: 1910out:
1909 if (ret < 0) 1911 if (ret < 0) {
1910 bio_endio(bio, ret); 1912 bio->bi_error = ret;
1913 bio_endio(bio);
1914 }
1911 return ret; 1915 return ret;
1912} 1916}
1913 1917
@@ -7689,13 +7693,13 @@ struct btrfs_retry_complete {
7689 int uptodate; 7693 int uptodate;
7690}; 7694};
7691 7695
7692static void btrfs_retry_endio_nocsum(struct bio *bio, int err) 7696static void btrfs_retry_endio_nocsum(struct bio *bio)
7693{ 7697{
7694 struct btrfs_retry_complete *done = bio->bi_private; 7698 struct btrfs_retry_complete *done = bio->bi_private;
7695 struct bio_vec *bvec; 7699 struct bio_vec *bvec;
7696 int i; 7700 int i;
7697 7701
7698 if (err) 7702 if (bio->bi_error)
7699 goto end; 7703 goto end;
7700 7704
7701 done->uptodate = 1; 7705 done->uptodate = 1;
@@ -7744,7 +7748,7 @@ try_again:
7744 return 0; 7748 return 0;
7745} 7749}
7746 7750
7747static void btrfs_retry_endio(struct bio *bio, int err) 7751static void btrfs_retry_endio(struct bio *bio)
7748{ 7752{
7749 struct btrfs_retry_complete *done = bio->bi_private; 7753 struct btrfs_retry_complete *done = bio->bi_private;
7750 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); 7754 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio);
@@ -7753,7 +7757,7 @@ static void btrfs_retry_endio(struct bio *bio, int err)
7753 int ret; 7757 int ret;
7754 int i; 7758 int i;
7755 7759
7756 if (err) 7760 if (bio->bi_error)
7757 goto end; 7761 goto end;
7758 7762
7759 uptodate = 1; 7763 uptodate = 1;
@@ -7836,12 +7840,13 @@ static int btrfs_subio_endio_read(struct inode *inode,
7836 } 7840 }
7837} 7841}
7838 7842
7839static void btrfs_endio_direct_read(struct bio *bio, int err) 7843static void btrfs_endio_direct_read(struct bio *bio)
7840{ 7844{
7841 struct btrfs_dio_private *dip = bio->bi_private; 7845 struct btrfs_dio_private *dip = bio->bi_private;
7842 struct inode *inode = dip->inode; 7846 struct inode *inode = dip->inode;
7843 struct bio *dio_bio; 7847 struct bio *dio_bio;
7844 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); 7848 struct btrfs_io_bio *io_bio = btrfs_io_bio(bio);
7849 int err = bio->bi_error;
7845 7850
7846 if (dip->flags & BTRFS_DIO_ORIG_BIO_SUBMITTED) 7851 if (dip->flags & BTRFS_DIO_ORIG_BIO_SUBMITTED)
7847 err = btrfs_subio_endio_read(inode, io_bio, err); 7852 err = btrfs_subio_endio_read(inode, io_bio, err);
@@ -7852,17 +7857,14 @@ static void btrfs_endio_direct_read(struct bio *bio, int err)
7852 7857
7853 kfree(dip); 7858 kfree(dip);
7854 7859
7855 /* If we had a csum failure make sure to clear the uptodate flag */ 7860 dio_end_io(dio_bio, bio->bi_error);
7856 if (err)
7857 clear_bit(BIO_UPTODATE, &dio_bio->bi_flags);
7858 dio_end_io(dio_bio, err);
7859 7861
7860 if (io_bio->end_io) 7862 if (io_bio->end_io)
7861 io_bio->end_io(io_bio, err); 7863 io_bio->end_io(io_bio, err);
7862 bio_put(bio); 7864 bio_put(bio);
7863} 7865}
7864 7866
7865static void btrfs_endio_direct_write(struct bio *bio, int err) 7867static void btrfs_endio_direct_write(struct bio *bio)
7866{ 7868{
7867 struct btrfs_dio_private *dip = bio->bi_private; 7869 struct btrfs_dio_private *dip = bio->bi_private;
7868 struct inode *inode = dip->inode; 7870 struct inode *inode = dip->inode;
@@ -7876,7 +7878,8 @@ static void btrfs_endio_direct_write(struct bio *bio, int err)
7876again: 7878again:
7877 ret = btrfs_dec_test_first_ordered_pending(inode, &ordered, 7879 ret = btrfs_dec_test_first_ordered_pending(inode, &ordered,
7878 &ordered_offset, 7880 &ordered_offset,
7879 ordered_bytes, !err); 7881 ordered_bytes,
7882 !bio->bi_error);
7880 if (!ret) 7883 if (!ret)
7881 goto out_test; 7884 goto out_test;
7882 7885
@@ -7899,10 +7902,7 @@ out_test:
7899 7902
7900 kfree(dip); 7903 kfree(dip);
7901 7904
7902 /* If we had an error make sure to clear the uptodate flag */ 7905 dio_end_io(dio_bio, bio->bi_error);
7903 if (err)
7904 clear_bit(BIO_UPTODATE, &dio_bio->bi_flags);
7905 dio_end_io(dio_bio, err);
7906 bio_put(bio); 7906 bio_put(bio);
7907} 7907}
7908 7908
@@ -7917,9 +7917,10 @@ static int __btrfs_submit_bio_start_direct_io(struct inode *inode, int rw,
7917 return 0; 7917 return 0;
7918} 7918}
7919 7919
7920static void btrfs_end_dio_bio(struct bio *bio, int err) 7920static void btrfs_end_dio_bio(struct bio *bio)
7921{ 7921{
7922 struct btrfs_dio_private *dip = bio->bi_private; 7922 struct btrfs_dio_private *dip = bio->bi_private;
7923 int err = bio->bi_error;
7923 7924
7924 if (err) 7925 if (err)
7925 btrfs_warn(BTRFS_I(dip->inode)->root->fs_info, 7926 btrfs_warn(BTRFS_I(dip->inode)->root->fs_info,
@@ -7948,8 +7949,8 @@ static void btrfs_end_dio_bio(struct bio *bio, int err)
7948 if (dip->errors) { 7949 if (dip->errors) {
7949 bio_io_error(dip->orig_bio); 7950 bio_io_error(dip->orig_bio);
7950 } else { 7951 } else {
7951 set_bit(BIO_UPTODATE, &dip->dio_bio->bi_flags); 7952 dip->dio_bio->bi_error = 0;
7952 bio_endio(dip->orig_bio, 0); 7953 bio_endio(dip->orig_bio);
7953 } 7954 }
7954out: 7955out:
7955 bio_put(bio); 7956 bio_put(bio);
@@ -8220,7 +8221,8 @@ free_ordered:
8220 * callbacks - they require an allocated dip and a clone of dio_bio. 8221 * callbacks - they require an allocated dip and a clone of dio_bio.
8221 */ 8222 */
8222 if (io_bio && dip) { 8223 if (io_bio && dip) {
8223 bio_endio(io_bio, ret); 8224 io_bio->bi_error = -EIO;
8225 bio_endio(io_bio);
8224 /* 8226 /*
8225 * The end io callbacks free our dip, do the final put on io_bio 8227 * The end io callbacks free our dip, do the final put on io_bio
8226 * and all the cleanup and final put for dio_bio (through 8228 * and all the cleanup and final put for dio_bio (through
@@ -8247,7 +8249,7 @@ free_ordered:
8247 unlock_extent(&BTRFS_I(inode)->io_tree, file_offset, 8249 unlock_extent(&BTRFS_I(inode)->io_tree, file_offset,
8248 file_offset + dio_bio->bi_iter.bi_size - 1); 8250 file_offset + dio_bio->bi_iter.bi_size - 1);
8249 } 8251 }
8250 clear_bit(BIO_UPTODATE, &dio_bio->bi_flags); 8252 dio_bio->bi_error = -EIO;
8251 /* 8253 /*
8252 * Releases and cleans up our dio_bio, no need to bio_put() 8254 * Releases and cleans up our dio_bio, no need to bio_put()
8253 * nor bio_endio()/bio_io_error() against dio_bio. 8255 * nor bio_endio()/bio_io_error() against dio_bio.
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index fa72068bd256..0a02e24900aa 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -851,7 +851,7 @@ static void free_raid_bio(struct btrfs_raid_bio *rbio)
851 * this frees the rbio and runs through all the bios in the 851 * this frees the rbio and runs through all the bios in the
852 * bio_list and calls end_io on them 852 * bio_list and calls end_io on them
853 */ 853 */
854static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, int err, int uptodate) 854static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, int err)
855{ 855{
856 struct bio *cur = bio_list_get(&rbio->bio_list); 856 struct bio *cur = bio_list_get(&rbio->bio_list);
857 struct bio *next; 857 struct bio *next;
@@ -864,9 +864,8 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, int err, int uptodate)
864 while (cur) { 864 while (cur) {
865 next = cur->bi_next; 865 next = cur->bi_next;
866 cur->bi_next = NULL; 866 cur->bi_next = NULL;
867 if (uptodate) 867 cur->bi_error = err;
868 set_bit(BIO_UPTODATE, &cur->bi_flags); 868 bio_endio(cur);
869 bio_endio(cur, err);
870 cur = next; 869 cur = next;
871 } 870 }
872} 871}
@@ -875,9 +874,10 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, int err, int uptodate)
875 * end io function used by finish_rmw. When we finally 874 * end io function used by finish_rmw. When we finally
876 * get here, we've written a full stripe 875 * get here, we've written a full stripe
877 */ 876 */
878static void raid_write_end_io(struct bio *bio, int err) 877static void raid_write_end_io(struct bio *bio)
879{ 878{
880 struct btrfs_raid_bio *rbio = bio->bi_private; 879 struct btrfs_raid_bio *rbio = bio->bi_private;
880 int err = bio->bi_error;
881 881
882 if (err) 882 if (err)
883 fail_bio_stripe(rbio, bio); 883 fail_bio_stripe(rbio, bio);
@@ -893,7 +893,7 @@ static void raid_write_end_io(struct bio *bio, int err)
893 if (atomic_read(&rbio->error) > rbio->bbio->max_errors) 893 if (atomic_read(&rbio->error) > rbio->bbio->max_errors)
894 err = -EIO; 894 err = -EIO;
895 895
896 rbio_orig_end_io(rbio, err, 0); 896 rbio_orig_end_io(rbio, err);
897 return; 897 return;
898} 898}
899 899
@@ -1071,7 +1071,7 @@ static int rbio_add_io_page(struct btrfs_raid_bio *rbio,
1071 * devices or if they are not contiguous 1071 * devices or if they are not contiguous
1072 */ 1072 */
1073 if (last_end == disk_start && stripe->dev->bdev && 1073 if (last_end == disk_start && stripe->dev->bdev &&
1074 test_bit(BIO_UPTODATE, &last->bi_flags) && 1074 !last->bi_error &&
1075 last->bi_bdev == stripe->dev->bdev) { 1075 last->bi_bdev == stripe->dev->bdev) {
1076 ret = bio_add_page(last, page, PAGE_CACHE_SIZE, 0); 1076 ret = bio_add_page(last, page, PAGE_CACHE_SIZE, 0);
1077 if (ret == PAGE_CACHE_SIZE) 1077 if (ret == PAGE_CACHE_SIZE)
@@ -1087,7 +1087,6 @@ static int rbio_add_io_page(struct btrfs_raid_bio *rbio,
1087 bio->bi_iter.bi_size = 0; 1087 bio->bi_iter.bi_size = 0;
1088 bio->bi_bdev = stripe->dev->bdev; 1088 bio->bi_bdev = stripe->dev->bdev;
1089 bio->bi_iter.bi_sector = disk_start >> 9; 1089 bio->bi_iter.bi_sector = disk_start >> 9;
1090 set_bit(BIO_UPTODATE, &bio->bi_flags);
1091 1090
1092 bio_add_page(bio, page, PAGE_CACHE_SIZE, 0); 1091 bio_add_page(bio, page, PAGE_CACHE_SIZE, 0);
1093 bio_list_add(bio_list, bio); 1092 bio_list_add(bio_list, bio);
@@ -1312,13 +1311,12 @@ write_data:
1312 1311
1313 bio->bi_private = rbio; 1312 bio->bi_private = rbio;
1314 bio->bi_end_io = raid_write_end_io; 1313 bio->bi_end_io = raid_write_end_io;
1315 BUG_ON(!test_bit(BIO_UPTODATE, &bio->bi_flags));
1316 submit_bio(WRITE, bio); 1314 submit_bio(WRITE, bio);
1317 } 1315 }
1318 return; 1316 return;
1319 1317
1320cleanup: 1318cleanup:
1321 rbio_orig_end_io(rbio, -EIO, 0); 1319 rbio_orig_end_io(rbio, -EIO);
1322} 1320}
1323 1321
1324/* 1322/*
@@ -1441,11 +1439,11 @@ static void set_bio_pages_uptodate(struct bio *bio)
1441 * This will usually kick off finish_rmw once all the bios are read in, but it 1439 * This will usually kick off finish_rmw once all the bios are read in, but it
1442 * may trigger parity reconstruction if we had any errors along the way 1440 * may trigger parity reconstruction if we had any errors along the way
1443 */ 1441 */
1444static void raid_rmw_end_io(struct bio *bio, int err) 1442static void raid_rmw_end_io(struct bio *bio)
1445{ 1443{
1446 struct btrfs_raid_bio *rbio = bio->bi_private; 1444 struct btrfs_raid_bio *rbio = bio->bi_private;
1447 1445
1448 if (err) 1446 if (bio->bi_error)
1449 fail_bio_stripe(rbio, bio); 1447 fail_bio_stripe(rbio, bio);
1450 else 1448 else
1451 set_bio_pages_uptodate(bio); 1449 set_bio_pages_uptodate(bio);
@@ -1455,7 +1453,6 @@ static void raid_rmw_end_io(struct bio *bio, int err)
1455 if (!atomic_dec_and_test(&rbio->stripes_pending)) 1453 if (!atomic_dec_and_test(&rbio->stripes_pending))
1456 return; 1454 return;
1457 1455
1458 err = 0;
1459 if (atomic_read(&rbio->error) > rbio->bbio->max_errors) 1456 if (atomic_read(&rbio->error) > rbio->bbio->max_errors)
1460 goto cleanup; 1457 goto cleanup;
1461 1458
@@ -1469,7 +1466,7 @@ static void raid_rmw_end_io(struct bio *bio, int err)
1469 1466
1470cleanup: 1467cleanup:
1471 1468
1472 rbio_orig_end_io(rbio, -EIO, 0); 1469 rbio_orig_end_io(rbio, -EIO);
1473} 1470}
1474 1471
1475static void async_rmw_stripe(struct btrfs_raid_bio *rbio) 1472static void async_rmw_stripe(struct btrfs_raid_bio *rbio)
@@ -1572,14 +1569,13 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)
1572 btrfs_bio_wq_end_io(rbio->fs_info, bio, 1569 btrfs_bio_wq_end_io(rbio->fs_info, bio,
1573 BTRFS_WQ_ENDIO_RAID56); 1570 BTRFS_WQ_ENDIO_RAID56);
1574 1571
1575 BUG_ON(!test_bit(BIO_UPTODATE, &bio->bi_flags));
1576 submit_bio(READ, bio); 1572 submit_bio(READ, bio);
1577 } 1573 }
1578 /* the actual write will happen once the reads are done */ 1574 /* the actual write will happen once the reads are done */
1579 return 0; 1575 return 0;
1580 1576
1581cleanup: 1577cleanup:
1582 rbio_orig_end_io(rbio, -EIO, 0); 1578 rbio_orig_end_io(rbio, -EIO);
1583 return -EIO; 1579 return -EIO;
1584 1580
1585finish: 1581finish:
@@ -1964,7 +1960,7 @@ cleanup_io:
1964 else 1960 else
1965 clear_bit(RBIO_CACHE_READY_BIT, &rbio->flags); 1961 clear_bit(RBIO_CACHE_READY_BIT, &rbio->flags);
1966 1962
1967 rbio_orig_end_io(rbio, err, err == 0); 1963 rbio_orig_end_io(rbio, err);
1968 } else if (err == 0) { 1964 } else if (err == 0) {
1969 rbio->faila = -1; 1965 rbio->faila = -1;
1970 rbio->failb = -1; 1966 rbio->failb = -1;
@@ -1976,7 +1972,7 @@ cleanup_io:
1976 else 1972 else
1977 BUG(); 1973 BUG();
1978 } else { 1974 } else {
1979 rbio_orig_end_io(rbio, err, 0); 1975 rbio_orig_end_io(rbio, err);
1980 } 1976 }
1981} 1977}
1982 1978
@@ -1984,7 +1980,7 @@ cleanup_io:
1984 * This is called only for stripes we've read from disk to 1980 * This is called only for stripes we've read from disk to
1985 * reconstruct the parity. 1981 * reconstruct the parity.
1986 */ 1982 */
1987static void raid_recover_end_io(struct bio *bio, int err) 1983static void raid_recover_end_io(struct bio *bio)
1988{ 1984{
1989 struct btrfs_raid_bio *rbio = bio->bi_private; 1985 struct btrfs_raid_bio *rbio = bio->bi_private;
1990 1986
@@ -1992,7 +1988,7 @@ static void raid_recover_end_io(struct bio *bio, int err)
1992 * we only read stripe pages off the disk, set them 1988 * we only read stripe pages off the disk, set them
1993 * up to date if there were no errors 1989 * up to date if there were no errors
1994 */ 1990 */
1995 if (err) 1991 if (bio->bi_error)
1996 fail_bio_stripe(rbio, bio); 1992 fail_bio_stripe(rbio, bio);
1997 else 1993 else
1998 set_bio_pages_uptodate(bio); 1994 set_bio_pages_uptodate(bio);
@@ -2002,7 +1998,7 @@ static void raid_recover_end_io(struct bio *bio, int err)
2002 return; 1998 return;
2003 1999
2004 if (atomic_read(&rbio->error) > rbio->bbio->max_errors) 2000 if (atomic_read(&rbio->error) > rbio->bbio->max_errors)
2005 rbio_orig_end_io(rbio, -EIO, 0); 2001 rbio_orig_end_io(rbio, -EIO);
2006 else 2002 else
2007 __raid_recover_end_io(rbio); 2003 __raid_recover_end_io(rbio);
2008} 2004}
@@ -2094,7 +2090,6 @@ static int __raid56_parity_recover(struct btrfs_raid_bio *rbio)
2094 btrfs_bio_wq_end_io(rbio->fs_info, bio, 2090 btrfs_bio_wq_end_io(rbio->fs_info, bio,
2095 BTRFS_WQ_ENDIO_RAID56); 2091 BTRFS_WQ_ENDIO_RAID56);
2096 2092
2097 BUG_ON(!test_bit(BIO_UPTODATE, &bio->bi_flags));
2098 submit_bio(READ, bio); 2093 submit_bio(READ, bio);
2099 } 2094 }
2100out: 2095out:
@@ -2102,7 +2097,7 @@ out:
2102 2097
2103cleanup: 2098cleanup:
2104 if (rbio->operation == BTRFS_RBIO_READ_REBUILD) 2099 if (rbio->operation == BTRFS_RBIO_READ_REBUILD)
2105 rbio_orig_end_io(rbio, -EIO, 0); 2100 rbio_orig_end_io(rbio, -EIO);
2106 return -EIO; 2101 return -EIO;
2107} 2102}
2108 2103
@@ -2277,11 +2272,12 @@ static int alloc_rbio_essential_pages(struct btrfs_raid_bio *rbio)
2277 * end io function used by finish_rmw. When we finally 2272 * end io function used by finish_rmw. When we finally
2278 * get here, we've written a full stripe 2273 * get here, we've written a full stripe
2279 */ 2274 */
2280static void raid_write_parity_end_io(struct bio *bio, int err) 2275static void raid_write_parity_end_io(struct bio *bio)
2281{ 2276{
2282 struct btrfs_raid_bio *rbio = bio->bi_private; 2277 struct btrfs_raid_bio *rbio = bio->bi_private;
2278 int err = bio->bi_error;
2283 2279
2284 if (err) 2280 if (bio->bi_error)
2285 fail_bio_stripe(rbio, bio); 2281 fail_bio_stripe(rbio, bio);
2286 2282
2287 bio_put(bio); 2283 bio_put(bio);
@@ -2294,7 +2290,7 @@ static void raid_write_parity_end_io(struct bio *bio, int err)
2294 if (atomic_read(&rbio->error)) 2290 if (atomic_read(&rbio->error))
2295 err = -EIO; 2291 err = -EIO;
2296 2292
2297 rbio_orig_end_io(rbio, err, 0); 2293 rbio_orig_end_io(rbio, err);
2298} 2294}
2299 2295
2300static noinline void finish_parity_scrub(struct btrfs_raid_bio *rbio, 2296static noinline void finish_parity_scrub(struct btrfs_raid_bio *rbio,
@@ -2437,7 +2433,7 @@ submit_write:
2437 nr_data = bio_list_size(&bio_list); 2433 nr_data = bio_list_size(&bio_list);
2438 if (!nr_data) { 2434 if (!nr_data) {
2439 /* Every parity is right */ 2435 /* Every parity is right */
2440 rbio_orig_end_io(rbio, 0, 0); 2436 rbio_orig_end_io(rbio, 0);
2441 return; 2437 return;
2442 } 2438 }
2443 2439
@@ -2450,13 +2446,12 @@ submit_write:
2450 2446
2451 bio->bi_private = rbio; 2447 bio->bi_private = rbio;
2452 bio->bi_end_io = raid_write_parity_end_io; 2448 bio->bi_end_io = raid_write_parity_end_io;
2453 BUG_ON(!test_bit(BIO_UPTODATE, &bio->bi_flags));
2454 submit_bio(WRITE, bio); 2449 submit_bio(WRITE, bio);
2455 } 2450 }
2456 return; 2451 return;
2457 2452
2458cleanup: 2453cleanup:
2459 rbio_orig_end_io(rbio, -EIO, 0); 2454 rbio_orig_end_io(rbio, -EIO);
2460} 2455}
2461 2456
2462static inline int is_data_stripe(struct btrfs_raid_bio *rbio, int stripe) 2457static inline int is_data_stripe(struct btrfs_raid_bio *rbio, int stripe)
@@ -2524,7 +2519,7 @@ static void validate_rbio_for_parity_scrub(struct btrfs_raid_bio *rbio)
2524 return; 2519 return;
2525 2520
2526cleanup: 2521cleanup:
2527 rbio_orig_end_io(rbio, -EIO, 0); 2522 rbio_orig_end_io(rbio, -EIO);
2528} 2523}
2529 2524
2530/* 2525/*
@@ -2535,11 +2530,11 @@ cleanup:
2535 * This will usually kick off finish_rmw once all the bios are read in, but it 2530 * This will usually kick off finish_rmw once all the bios are read in, but it
2536 * may trigger parity reconstruction if we had any errors along the way 2531 * may trigger parity reconstruction if we had any errors along the way
2537 */ 2532 */
2538static void raid56_parity_scrub_end_io(struct bio *bio, int err) 2533static void raid56_parity_scrub_end_io(struct bio *bio)
2539{ 2534{
2540 struct btrfs_raid_bio *rbio = bio->bi_private; 2535 struct btrfs_raid_bio *rbio = bio->bi_private;
2541 2536
2542 if (err) 2537 if (bio->bi_error)
2543 fail_bio_stripe(rbio, bio); 2538 fail_bio_stripe(rbio, bio);
2544 else 2539 else
2545 set_bio_pages_uptodate(bio); 2540 set_bio_pages_uptodate(bio);
@@ -2632,14 +2627,13 @@ static void raid56_parity_scrub_stripe(struct btrfs_raid_bio *rbio)
2632 btrfs_bio_wq_end_io(rbio->fs_info, bio, 2627 btrfs_bio_wq_end_io(rbio->fs_info, bio,
2633 BTRFS_WQ_ENDIO_RAID56); 2628 BTRFS_WQ_ENDIO_RAID56);
2634 2629
2635 BUG_ON(!test_bit(BIO_UPTODATE, &bio->bi_flags));
2636 submit_bio(READ, bio); 2630 submit_bio(READ, bio);
2637 } 2631 }
2638 /* the actual write will happen once the reads are done */ 2632 /* the actual write will happen once the reads are done */
2639 return; 2633 return;
2640 2634
2641cleanup: 2635cleanup:
2642 rbio_orig_end_io(rbio, -EIO, 0); 2636 rbio_orig_end_io(rbio, -EIO);
2643 return; 2637 return;
2644 2638
2645finish: 2639finish:
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 94db0fa5225a..ebb8260186fe 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -278,7 +278,7 @@ static int scrub_pages(struct scrub_ctx *sctx, u64 logical, u64 len,
278 u64 physical, struct btrfs_device *dev, u64 flags, 278 u64 physical, struct btrfs_device *dev, u64 flags,
279 u64 gen, int mirror_num, u8 *csum, int force, 279 u64 gen, int mirror_num, u8 *csum, int force,
280 u64 physical_for_dev_replace); 280 u64 physical_for_dev_replace);
281static void scrub_bio_end_io(struct bio *bio, int err); 281static void scrub_bio_end_io(struct bio *bio);
282static void scrub_bio_end_io_worker(struct btrfs_work *work); 282static void scrub_bio_end_io_worker(struct btrfs_work *work);
283static void scrub_block_complete(struct scrub_block *sblock); 283static void scrub_block_complete(struct scrub_block *sblock);
284static void scrub_remap_extent(struct btrfs_fs_info *fs_info, 284static void scrub_remap_extent(struct btrfs_fs_info *fs_info,
@@ -295,7 +295,7 @@ static void scrub_free_wr_ctx(struct scrub_wr_ctx *wr_ctx);
295static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx, 295static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx,
296 struct scrub_page *spage); 296 struct scrub_page *spage);
297static void scrub_wr_submit(struct scrub_ctx *sctx); 297static void scrub_wr_submit(struct scrub_ctx *sctx);
298static void scrub_wr_bio_end_io(struct bio *bio, int err); 298static void scrub_wr_bio_end_io(struct bio *bio);
299static void scrub_wr_bio_end_io_worker(struct btrfs_work *work); 299static void scrub_wr_bio_end_io_worker(struct btrfs_work *work);
300static int write_page_nocow(struct scrub_ctx *sctx, 300static int write_page_nocow(struct scrub_ctx *sctx,
301 u64 physical_for_dev_replace, struct page *page); 301 u64 physical_for_dev_replace, struct page *page);
@@ -1429,11 +1429,11 @@ struct scrub_bio_ret {
1429 int error; 1429 int error;
1430}; 1430};
1431 1431
1432static void scrub_bio_wait_endio(struct bio *bio, int error) 1432static void scrub_bio_wait_endio(struct bio *bio)
1433{ 1433{
1434 struct scrub_bio_ret *ret = bio->bi_private; 1434 struct scrub_bio_ret *ret = bio->bi_private;
1435 1435
1436 ret->error = error; 1436 ret->error = bio->bi_error;
1437 complete(&ret->event); 1437 complete(&ret->event);
1438} 1438}
1439 1439
@@ -1790,12 +1790,12 @@ static void scrub_wr_submit(struct scrub_ctx *sctx)
1790 btrfsic_submit_bio(WRITE, sbio->bio); 1790 btrfsic_submit_bio(WRITE, sbio->bio);
1791} 1791}
1792 1792
1793static void scrub_wr_bio_end_io(struct bio *bio, int err) 1793static void scrub_wr_bio_end_io(struct bio *bio)
1794{ 1794{
1795 struct scrub_bio *sbio = bio->bi_private; 1795 struct scrub_bio *sbio = bio->bi_private;
1796 struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info; 1796 struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info;
1797 1797
1798 sbio->err = err; 1798 sbio->err = bio->bi_error;
1799 sbio->bio = bio; 1799 sbio->bio = bio;
1800 1800
1801 btrfs_init_work(&sbio->work, btrfs_scrubwrc_helper, 1801 btrfs_init_work(&sbio->work, btrfs_scrubwrc_helper,
@@ -2098,7 +2098,7 @@ static void scrub_submit(struct scrub_ctx *sctx)
2098 */ 2098 */
2099 printk_ratelimited(KERN_WARNING 2099 printk_ratelimited(KERN_WARNING
2100 "BTRFS: scrub_submit(bio bdev == NULL) is unexpected!\n"); 2100 "BTRFS: scrub_submit(bio bdev == NULL) is unexpected!\n");
2101 bio_endio(sbio->bio, -EIO); 2101 bio_io_error(sbio->bio);
2102 } else { 2102 } else {
2103 btrfsic_submit_bio(READ, sbio->bio); 2103 btrfsic_submit_bio(READ, sbio->bio);
2104 } 2104 }
@@ -2260,12 +2260,12 @@ leave_nomem:
2260 return 0; 2260 return 0;
2261} 2261}
2262 2262
2263static void scrub_bio_end_io(struct bio *bio, int err) 2263static void scrub_bio_end_io(struct bio *bio)
2264{ 2264{
2265 struct scrub_bio *sbio = bio->bi_private; 2265 struct scrub_bio *sbio = bio->bi_private;
2266 struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info; 2266 struct btrfs_fs_info *fs_info = sbio->dev->dev_root->fs_info;
2267 2267
2268 sbio->err = err; 2268 sbio->err = bio->bi_error;
2269 sbio->bio = bio; 2269 sbio->bio = bio;
2270 2270
2271 btrfs_queue_work(fs_info->scrub_workers, &sbio->work); 2271 btrfs_queue_work(fs_info->scrub_workers, &sbio->work);
@@ -2672,11 +2672,11 @@ static void scrub_parity_bio_endio_worker(struct btrfs_work *work)
2672 scrub_pending_bio_dec(sctx); 2672 scrub_pending_bio_dec(sctx);
2673} 2673}
2674 2674
2675static void scrub_parity_bio_endio(struct bio *bio, int error) 2675static void scrub_parity_bio_endio(struct bio *bio)
2676{ 2676{
2677 struct scrub_parity *sparity = (struct scrub_parity *)bio->bi_private; 2677 struct scrub_parity *sparity = (struct scrub_parity *)bio->bi_private;
2678 2678
2679 if (error) 2679 if (bio->bi_error)
2680 bitmap_or(sparity->ebitmap, sparity->ebitmap, sparity->dbitmap, 2680 bitmap_or(sparity->ebitmap, sparity->ebitmap, sparity->dbitmap,
2681 sparity->nsectors); 2681 sparity->nsectors);
2682 2682
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index fbe7c104531c..8f2ca18c71f4 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5741,23 +5741,23 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
5741 return 0; 5741 return 0;
5742} 5742}
5743 5743
5744static inline void btrfs_end_bbio(struct btrfs_bio *bbio, struct bio *bio, int err) 5744static inline void btrfs_end_bbio(struct btrfs_bio *bbio, struct bio *bio)
5745{ 5745{
5746 bio->bi_private = bbio->private; 5746 bio->bi_private = bbio->private;
5747 bio->bi_end_io = bbio->end_io; 5747 bio->bi_end_io = bbio->end_io;
5748 bio_endio(bio, err); 5748 bio_endio(bio);
5749 5749
5750 btrfs_put_bbio(bbio); 5750 btrfs_put_bbio(bbio);
5751} 5751}
5752 5752
5753static void btrfs_end_bio(struct bio *bio, int err) 5753static void btrfs_end_bio(struct bio *bio)
5754{ 5754{
5755 struct btrfs_bio *bbio = bio->bi_private; 5755 struct btrfs_bio *bbio = bio->bi_private;
5756 int is_orig_bio = 0; 5756 int is_orig_bio = 0;
5757 5757
5758 if (err) { 5758 if (bio->bi_error) {
5759 atomic_inc(&bbio->error); 5759 atomic_inc(&bbio->error);
5760 if (err == -EIO || err == -EREMOTEIO) { 5760 if (bio->bi_error == -EIO || bio->bi_error == -EREMOTEIO) {
5761 unsigned int stripe_index = 5761 unsigned int stripe_index =
5762 btrfs_io_bio(bio)->stripe_index; 5762 btrfs_io_bio(bio)->stripe_index;
5763 struct btrfs_device *dev; 5763 struct btrfs_device *dev;
@@ -5795,17 +5795,16 @@ static void btrfs_end_bio(struct bio *bio, int err)
5795 * beyond the tolerance of the btrfs bio 5795 * beyond the tolerance of the btrfs bio
5796 */ 5796 */
5797 if (atomic_read(&bbio->error) > bbio->max_errors) { 5797 if (atomic_read(&bbio->error) > bbio->max_errors) {
5798 err = -EIO; 5798 bio->bi_error = -EIO;
5799 } else { 5799 } else {
5800 /* 5800 /*
5801 * this bio is actually up to date, we didn't 5801 * this bio is actually up to date, we didn't
5802 * go over the max number of errors 5802 * go over the max number of errors
5803 */ 5803 */
5804 set_bit(BIO_UPTODATE, &bio->bi_flags); 5804 bio->bi_error = 0;
5805 err = 0;
5806 } 5805 }
5807 5806
5808 btrfs_end_bbio(bbio, bio, err); 5807 btrfs_end_bbio(bbio, bio);
5809 } else if (!is_orig_bio) { 5808 } else if (!is_orig_bio) {
5810 bio_put(bio); 5809 bio_put(bio);
5811 } 5810 }
@@ -5826,7 +5825,7 @@ static noinline void btrfs_schedule_bio(struct btrfs_root *root,
5826 struct btrfs_pending_bios *pending_bios; 5825 struct btrfs_pending_bios *pending_bios;
5827 5826
5828 if (device->missing || !device->bdev) { 5827 if (device->missing || !device->bdev) {
5829 bio_endio(bio, -EIO); 5828 bio_io_error(bio);
5830 return; 5829 return;
5831 } 5830 }
5832 5831
@@ -5973,8 +5972,8 @@ static void bbio_error(struct btrfs_bio *bbio, struct bio *bio, u64 logical)
5973 5972
5974 btrfs_io_bio(bio)->mirror_num = bbio->mirror_num; 5973 btrfs_io_bio(bio)->mirror_num = bbio->mirror_num;
5975 bio->bi_iter.bi_sector = logical >> 9; 5974 bio->bi_iter.bi_sector = logical >> 9;
5976 5975 bio->bi_error = -EIO;
5977 btrfs_end_bbio(bbio, bio, -EIO); 5976 btrfs_end_bbio(bbio, bio);
5978 } 5977 }
5979} 5978}
5980 5979