aboutsummaryrefslogtreecommitdiffstats
path: root/fs
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
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')
-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
-rw-r--r--fs/buffer.c4
-rw-r--r--fs/direct-io.c13
-rw-r--r--fs/ext4/page-io.c15
-rw-r--r--fs/ext4/readpage.c6
-rw-r--r--fs/f2fs/data.c10
-rw-r--r--fs/gfs2/lops.c10
-rw-r--r--fs/gfs2/ops_fstype.c6
-rw-r--r--fs/jfs/jfs_logmgr.c8
-rw-r--r--fs/jfs/jfs_metapage.c8
-rw-r--r--fs/logfs/dev_bdev.c12
-rw-r--r--fs/mpage.c4
-rw-r--r--fs/nfs/blocklayout/blocklayout.c14
-rw-r--r--fs/nilfs2/segbuf.c5
-rw-r--r--fs/ocfs2/cluster/heartbeat.c9
-rw-r--r--fs/xfs/xfs_aops.c5
-rw-r--r--fs/xfs/xfs_buf.c7
24 files changed, 187 insertions, 205 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
diff --git a/fs/buffer.c b/fs/buffer.c
index 1cf7a53a0277..7a49bb84ecb5 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2957,14 +2957,14 @@ sector_t generic_block_bmap(struct address_space *mapping, sector_t block,
2957} 2957}
2958EXPORT_SYMBOL(generic_block_bmap); 2958EXPORT_SYMBOL(generic_block_bmap);
2959 2959
2960static void end_bio_bh_io_sync(struct bio *bio, int err) 2960static void end_bio_bh_io_sync(struct bio *bio)
2961{ 2961{
2962 struct buffer_head *bh = bio->bi_private; 2962 struct buffer_head *bh = bio->bi_private;
2963 2963
2964 if (unlikely (test_bit(BIO_QUIET,&bio->bi_flags))) 2964 if (unlikely (test_bit(BIO_QUIET,&bio->bi_flags)))
2965 set_bit(BH_Quiet, &bh->b_state); 2965 set_bit(BH_Quiet, &bh->b_state);
2966 2966
2967 bh->b_end_io(bh, test_bit(BIO_UPTODATE, &bio->bi_flags)); 2967 bh->b_end_io(bh, !bio->bi_error);
2968 bio_put(bio); 2968 bio_put(bio);
2969} 2969}
2970 2970
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 745d2342651a..e1639c8c14d5 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -285,7 +285,7 @@ static int dio_bio_complete(struct dio *dio, struct bio *bio);
285/* 285/*
286 * Asynchronous IO callback. 286 * Asynchronous IO callback.
287 */ 287 */
288static void dio_bio_end_aio(struct bio *bio, int error) 288static void dio_bio_end_aio(struct bio *bio)
289{ 289{
290 struct dio *dio = bio->bi_private; 290 struct dio *dio = bio->bi_private;
291 unsigned long remaining; 291 unsigned long remaining;
@@ -318,7 +318,7 @@ static void dio_bio_end_aio(struct bio *bio, int error)
318 * During I/O bi_private points at the dio. After I/O, bi_private is used to 318 * During I/O bi_private points at the dio. After I/O, bi_private is used to
319 * implement a singly-linked list of completed BIOs, at dio->bio_list. 319 * implement a singly-linked list of completed BIOs, at dio->bio_list.
320 */ 320 */
321static void dio_bio_end_io(struct bio *bio, int error) 321static void dio_bio_end_io(struct bio *bio)
322{ 322{
323 struct dio *dio = bio->bi_private; 323 struct dio *dio = bio->bi_private;
324 unsigned long flags; 324 unsigned long flags;
@@ -345,9 +345,9 @@ void dio_end_io(struct bio *bio, int error)
345 struct dio *dio = bio->bi_private; 345 struct dio *dio = bio->bi_private;
346 346
347 if (dio->is_async) 347 if (dio->is_async)
348 dio_bio_end_aio(bio, error); 348 dio_bio_end_aio(bio);
349 else 349 else
350 dio_bio_end_io(bio, error); 350 dio_bio_end_io(bio);
351} 351}
352EXPORT_SYMBOL_GPL(dio_end_io); 352EXPORT_SYMBOL_GPL(dio_end_io);
353 353
@@ -457,11 +457,10 @@ static struct bio *dio_await_one(struct dio *dio)
457 */ 457 */
458static int dio_bio_complete(struct dio *dio, struct bio *bio) 458static int dio_bio_complete(struct dio *dio, struct bio *bio)
459{ 459{
460 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
461 struct bio_vec *bvec; 460 struct bio_vec *bvec;
462 unsigned i; 461 unsigned i;
463 462
464 if (!uptodate) 463 if (bio->bi_error)
465 dio->io_error = -EIO; 464 dio->io_error = -EIO;
466 465
467 if (dio->is_async && dio->rw == READ) { 466 if (dio->is_async && dio->rw == READ) {
@@ -476,7 +475,7 @@ static int dio_bio_complete(struct dio *dio, struct bio *bio)
476 } 475 }
477 bio_put(bio); 476 bio_put(bio);
478 } 477 }
479 return uptodate ? 0 : -EIO; 478 return bio->bi_error;
480} 479}
481 480
482/* 481/*
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 5602450f03f6..aa95566f14be 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -61,7 +61,6 @@ static void buffer_io_error(struct buffer_head *bh)
61static void ext4_finish_bio(struct bio *bio) 61static void ext4_finish_bio(struct bio *bio)
62{ 62{
63 int i; 63 int i;
64 int error = !test_bit(BIO_UPTODATE, &bio->bi_flags);
65 struct bio_vec *bvec; 64 struct bio_vec *bvec;
66 65
67 bio_for_each_segment_all(bvec, bio, i) { 66 bio_for_each_segment_all(bvec, bio, i) {
@@ -88,7 +87,7 @@ static void ext4_finish_bio(struct bio *bio)
88 } 87 }
89#endif 88#endif
90 89
91 if (error) { 90 if (bio->bi_error) {
92 SetPageError(page); 91 SetPageError(page);
93 set_bit(AS_EIO, &page->mapping->flags); 92 set_bit(AS_EIO, &page->mapping->flags);
94 } 93 }
@@ -107,7 +106,7 @@ static void ext4_finish_bio(struct bio *bio)
107 continue; 106 continue;
108 } 107 }
109 clear_buffer_async_write(bh); 108 clear_buffer_async_write(bh);
110 if (error) 109 if (bio->bi_error)
111 buffer_io_error(bh); 110 buffer_io_error(bh);
112 } while ((bh = bh->b_this_page) != head); 111 } while ((bh = bh->b_this_page) != head);
113 bit_spin_unlock(BH_Uptodate_Lock, &head->b_state); 112 bit_spin_unlock(BH_Uptodate_Lock, &head->b_state);
@@ -310,27 +309,25 @@ ext4_io_end_t *ext4_get_io_end(ext4_io_end_t *io_end)
310} 309}
311 310
312/* BIO completion function for page writeback */ 311/* BIO completion function for page writeback */
313static void ext4_end_bio(struct bio *bio, int error) 312static void ext4_end_bio(struct bio *bio)
314{ 313{
315 ext4_io_end_t *io_end = bio->bi_private; 314 ext4_io_end_t *io_end = bio->bi_private;
316 sector_t bi_sector = bio->bi_iter.bi_sector; 315 sector_t bi_sector = bio->bi_iter.bi_sector;
317 316
318 BUG_ON(!io_end); 317 BUG_ON(!io_end);
319 bio->bi_end_io = NULL; 318 bio->bi_end_io = NULL;
320 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
321 error = 0;
322 319
323 if (error) { 320 if (bio->bi_error) {
324 struct inode *inode = io_end->inode; 321 struct inode *inode = io_end->inode;
325 322
326 ext4_warning(inode->i_sb, "I/O error %d writing to inode %lu " 323 ext4_warning(inode->i_sb, "I/O error %d writing to inode %lu "
327 "(offset %llu size %ld starting block %llu)", 324 "(offset %llu size %ld starting block %llu)",
328 error, inode->i_ino, 325 bio->bi_error, inode->i_ino,
329 (unsigned long long) io_end->offset, 326 (unsigned long long) io_end->offset,
330 (long) io_end->size, 327 (long) io_end->size,
331 (unsigned long long) 328 (unsigned long long)
332 bi_sector >> (inode->i_blkbits - 9)); 329 bi_sector >> (inode->i_blkbits - 9));
333 mapping_set_error(inode->i_mapping, error); 330 mapping_set_error(inode->i_mapping, bio->bi_error);
334 } 331 }
335 332
336 if (io_end->flag & EXT4_IO_END_UNWRITTEN) { 333 if (io_end->flag & EXT4_IO_END_UNWRITTEN) {
diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
index ec3ef93a52db..5de5b871c178 100644
--- a/fs/ext4/readpage.c
+++ b/fs/ext4/readpage.c
@@ -98,7 +98,7 @@ static inline bool ext4_bio_encrypted(struct bio *bio)
98 * status of that page is hard. See end_buffer_async_read() for the details. 98 * status of that page is hard. See end_buffer_async_read() for the details.
99 * There is no point in duplicating all that complexity. 99 * There is no point in duplicating all that complexity.
100 */ 100 */
101static void mpage_end_io(struct bio *bio, int err) 101static void mpage_end_io(struct bio *bio)
102{ 102{
103 struct bio_vec *bv; 103 struct bio_vec *bv;
104 int i; 104 int i;
@@ -106,7 +106,7 @@ static void mpage_end_io(struct bio *bio, int err)
106 if (ext4_bio_encrypted(bio)) { 106 if (ext4_bio_encrypted(bio)) {
107 struct ext4_crypto_ctx *ctx = bio->bi_private; 107 struct ext4_crypto_ctx *ctx = bio->bi_private;
108 108
109 if (err) { 109 if (bio->bi_error) {
110 ext4_release_crypto_ctx(ctx); 110 ext4_release_crypto_ctx(ctx);
111 } else { 111 } else {
112 INIT_WORK(&ctx->r.work, completion_pages); 112 INIT_WORK(&ctx->r.work, completion_pages);
@@ -118,7 +118,7 @@ static void mpage_end_io(struct bio *bio, int err)
118 bio_for_each_segment_all(bv, bio, i) { 118 bio_for_each_segment_all(bv, bio, i) {
119 struct page *page = bv->bv_page; 119 struct page *page = bv->bv_page;
120 120
121 if (!err) { 121 if (!bio->bi_error) {
122 SetPageUptodate(page); 122 SetPageUptodate(page);
123 } else { 123 } else {
124 ClearPageUptodate(page); 124 ClearPageUptodate(page);
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 9bedfa8dd3a5..8f0baa7ffb50 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -29,13 +29,13 @@
29static struct kmem_cache *extent_tree_slab; 29static struct kmem_cache *extent_tree_slab;
30static struct kmem_cache *extent_node_slab; 30static struct kmem_cache *extent_node_slab;
31 31
32static void f2fs_read_end_io(struct bio *bio, int err) 32static void f2fs_read_end_io(struct bio *bio)
33{ 33{
34 struct bio_vec *bvec; 34 struct bio_vec *bvec;
35 int i; 35 int i;
36 36
37 if (f2fs_bio_encrypted(bio)) { 37 if (f2fs_bio_encrypted(bio)) {
38 if (err) { 38 if (bio->bi_error) {
39 f2fs_release_crypto_ctx(bio->bi_private); 39 f2fs_release_crypto_ctx(bio->bi_private);
40 } else { 40 } else {
41 f2fs_end_io_crypto_work(bio->bi_private, bio); 41 f2fs_end_io_crypto_work(bio->bi_private, bio);
@@ -46,7 +46,7 @@ static void f2fs_read_end_io(struct bio *bio, int err)
46 bio_for_each_segment_all(bvec, bio, i) { 46 bio_for_each_segment_all(bvec, bio, i) {
47 struct page *page = bvec->bv_page; 47 struct page *page = bvec->bv_page;
48 48
49 if (!err) { 49 if (!bio->bi_error) {
50 SetPageUptodate(page); 50 SetPageUptodate(page);
51 } else { 51 } else {
52 ClearPageUptodate(page); 52 ClearPageUptodate(page);
@@ -57,7 +57,7 @@ static void f2fs_read_end_io(struct bio *bio, int err)
57 bio_put(bio); 57 bio_put(bio);
58} 58}
59 59
60static void f2fs_write_end_io(struct bio *bio, int err) 60static void f2fs_write_end_io(struct bio *bio)
61{ 61{
62 struct f2fs_sb_info *sbi = bio->bi_private; 62 struct f2fs_sb_info *sbi = bio->bi_private;
63 struct bio_vec *bvec; 63 struct bio_vec *bvec;
@@ -68,7 +68,7 @@ static void f2fs_write_end_io(struct bio *bio, int err)
68 68
69 f2fs_restore_and_release_control_page(&page); 69 f2fs_restore_and_release_control_page(&page);
70 70
71 if (unlikely(err)) { 71 if (unlikely(bio->bi_error)) {
72 set_page_dirty(page); 72 set_page_dirty(page);
73 set_bit(AS_EIO, &page->mapping->flags); 73 set_bit(AS_EIO, &page->mapping->flags);
74 f2fs_stop_checkpoint(sbi); 74 f2fs_stop_checkpoint(sbi);
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 2c1ae861dc94..c0a1b967deba 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -202,22 +202,22 @@ static void gfs2_end_log_write_bh(struct gfs2_sbd *sdp, struct bio_vec *bvec,
202 * 202 *
203 */ 203 */
204 204
205static void gfs2_end_log_write(struct bio *bio, int error) 205static void gfs2_end_log_write(struct bio *bio)
206{ 206{
207 struct gfs2_sbd *sdp = bio->bi_private; 207 struct gfs2_sbd *sdp = bio->bi_private;
208 struct bio_vec *bvec; 208 struct bio_vec *bvec;
209 struct page *page; 209 struct page *page;
210 int i; 210 int i;
211 211
212 if (error) { 212 if (bio->bi_error) {
213 sdp->sd_log_error = error; 213 sdp->sd_log_error = bio->bi_error;
214 fs_err(sdp, "Error %d writing to log\n", error); 214 fs_err(sdp, "Error %d writing to log\n", bio->bi_error);
215 } 215 }
216 216
217 bio_for_each_segment_all(bvec, bio, i) { 217 bio_for_each_segment_all(bvec, bio, i) {
218 page = bvec->bv_page; 218 page = bvec->bv_page;
219 if (page_has_buffers(page)) 219 if (page_has_buffers(page))
220 gfs2_end_log_write_bh(sdp, bvec, error); 220 gfs2_end_log_write_bh(sdp, bvec, bio->bi_error);
221 else 221 else
222 mempool_free(page, gfs2_page_pool); 222 mempool_free(page, gfs2_page_pool);
223 } 223 }
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 1e3a93f2f71d..02586e7eb964 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -171,14 +171,14 @@ static int gfs2_check_sb(struct gfs2_sbd *sdp, int silent)
171 return -EINVAL; 171 return -EINVAL;
172} 172}
173 173
174static void end_bio_io_page(struct bio *bio, int error) 174static void end_bio_io_page(struct bio *bio)
175{ 175{
176 struct page *page = bio->bi_private; 176 struct page *page = bio->bi_private;
177 177
178 if (!error) 178 if (!bio->bi_error)
179 SetPageUptodate(page); 179 SetPageUptodate(page);
180 else 180 else
181 pr_warn("error %d reading superblock\n", error); 181 pr_warn("error %d reading superblock\n", bio->bi_error);
182 unlock_page(page); 182 unlock_page(page);
183} 183}
184 184
diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index bc462dcd7a40..d301acfdb80d 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -2011,7 +2011,7 @@ static int lbmRead(struct jfs_log * log, int pn, struct lbuf ** bpp)
2011 /*check if journaling to disk has been disabled*/ 2011 /*check if journaling to disk has been disabled*/
2012 if (log->no_integrity) { 2012 if (log->no_integrity) {
2013 bio->bi_iter.bi_size = 0; 2013 bio->bi_iter.bi_size = 0;
2014 lbmIODone(bio, 0); 2014 lbmIODone(bio);
2015 } else { 2015 } else {
2016 submit_bio(READ_SYNC, bio); 2016 submit_bio(READ_SYNC, bio);
2017 } 2017 }
@@ -2158,7 +2158,7 @@ static void lbmStartIO(struct lbuf * bp)
2158 /* check if journaling to disk has been disabled */ 2158 /* check if journaling to disk has been disabled */
2159 if (log->no_integrity) { 2159 if (log->no_integrity) {
2160 bio->bi_iter.bi_size = 0; 2160 bio->bi_iter.bi_size = 0;
2161 lbmIODone(bio, 0); 2161 lbmIODone(bio);
2162 } else { 2162 } else {
2163 submit_bio(WRITE_SYNC, bio); 2163 submit_bio(WRITE_SYNC, bio);
2164 INCREMENT(lmStat.submitted); 2164 INCREMENT(lmStat.submitted);
@@ -2196,7 +2196,7 @@ static int lbmIOWait(struct lbuf * bp, int flag)
2196 * 2196 *
2197 * executed at INTIODONE level 2197 * executed at INTIODONE level
2198 */ 2198 */
2199static void lbmIODone(struct bio *bio, int error) 2199static void lbmIODone(struct bio *bio)
2200{ 2200{
2201 struct lbuf *bp = bio->bi_private; 2201 struct lbuf *bp = bio->bi_private;
2202 struct lbuf *nextbp, *tail; 2202 struct lbuf *nextbp, *tail;
@@ -2212,7 +2212,7 @@ static void lbmIODone(struct bio *bio, int error)
2212 2212
2213 bp->l_flag |= lbmDONE; 2213 bp->l_flag |= lbmDONE;
2214 2214
2215 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) { 2215 if (bio->bi_error) {
2216 bp->l_flag |= lbmERROR; 2216 bp->l_flag |= lbmERROR;
2217 2217
2218 jfs_err("lbmIODone: I/O error in JFS log"); 2218 jfs_err("lbmIODone: I/O error in JFS log");
diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
index 16a0922beb59..a3eb316b1ac3 100644
--- a/fs/jfs/jfs_metapage.c
+++ b/fs/jfs/jfs_metapage.c
@@ -276,11 +276,11 @@ static void last_read_complete(struct page *page)
276 unlock_page(page); 276 unlock_page(page);
277} 277}
278 278
279static void metapage_read_end_io(struct bio *bio, int err) 279static void metapage_read_end_io(struct bio *bio)
280{ 280{
281 struct page *page = bio->bi_private; 281 struct page *page = bio->bi_private;
282 282
283 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) { 283 if (bio->bi_error) {
284 printk(KERN_ERR "metapage_read_end_io: I/O error\n"); 284 printk(KERN_ERR "metapage_read_end_io: I/O error\n");
285 SetPageError(page); 285 SetPageError(page);
286 } 286 }
@@ -331,13 +331,13 @@ static void last_write_complete(struct page *page)
331 end_page_writeback(page); 331 end_page_writeback(page);
332} 332}
333 333
334static void metapage_write_end_io(struct bio *bio, int err) 334static void metapage_write_end_io(struct bio *bio)
335{ 335{
336 struct page *page = bio->bi_private; 336 struct page *page = bio->bi_private;
337 337
338 BUG_ON(!PagePrivate(page)); 338 BUG_ON(!PagePrivate(page));
339 339
340 if (! test_bit(BIO_UPTODATE, &bio->bi_flags)) { 340 if (bio->bi_error) {
341 printk(KERN_ERR "metapage_write_end_io: I/O error\n"); 341 printk(KERN_ERR "metapage_write_end_io: I/O error\n");
342 SetPageError(page); 342 SetPageError(page);
343 } 343 }
diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c
index 76279e11982d..cea0cc9878b7 100644
--- a/fs/logfs/dev_bdev.c
+++ b/fs/logfs/dev_bdev.c
@@ -53,16 +53,14 @@ static int bdev_readpage(void *_sb, struct page *page)
53 53
54static DECLARE_WAIT_QUEUE_HEAD(wq); 54static DECLARE_WAIT_QUEUE_HEAD(wq);
55 55
56static void writeseg_end_io(struct bio *bio, int err) 56static void writeseg_end_io(struct bio *bio)
57{ 57{
58 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
59 struct bio_vec *bvec; 58 struct bio_vec *bvec;
60 int i; 59 int i;
61 struct super_block *sb = bio->bi_private; 60 struct super_block *sb = bio->bi_private;
62 struct logfs_super *super = logfs_super(sb); 61 struct logfs_super *super = logfs_super(sb);
63 62
64 BUG_ON(!uptodate); /* FIXME: Retry io or write elsewhere */ 63 BUG_ON(bio->bi_error); /* FIXME: Retry io or write elsewhere */
65 BUG_ON(err);
66 64
67 bio_for_each_segment_all(bvec, bio, i) { 65 bio_for_each_segment_all(bvec, bio, i) {
68 end_page_writeback(bvec->bv_page); 66 end_page_writeback(bvec->bv_page);
@@ -153,14 +151,12 @@ static void bdev_writeseg(struct super_block *sb, u64 ofs, size_t len)
153} 151}
154 152
155 153
156static void erase_end_io(struct bio *bio, int err) 154static void erase_end_io(struct bio *bio)
157{ 155{
158 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
159 struct super_block *sb = bio->bi_private; 156 struct super_block *sb = bio->bi_private;
160 struct logfs_super *super = logfs_super(sb); 157 struct logfs_super *super = logfs_super(sb);
161 158
162 BUG_ON(!uptodate); /* FIXME: Retry io or write elsewhere */ 159 BUG_ON(bio->bi_error); /* FIXME: Retry io or write elsewhere */
163 BUG_ON(err);
164 BUG_ON(bio->bi_vcnt == 0); 160 BUG_ON(bio->bi_vcnt == 0);
165 bio_put(bio); 161 bio_put(bio);
166 if (atomic_dec_and_test(&super->s_pending_writes)) 162 if (atomic_dec_and_test(&super->s_pending_writes))
diff --git a/fs/mpage.c b/fs/mpage.c
index ca0244b69de8..abac9361b3f1 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -42,14 +42,14 @@
42 * status of that page is hard. See end_buffer_async_read() for the details. 42 * status of that page is hard. See end_buffer_async_read() for the details.
43 * There is no point in duplicating all that complexity. 43 * There is no point in duplicating all that complexity.
44 */ 44 */
45static void mpage_end_io(struct bio *bio, int err) 45static void mpage_end_io(struct bio *bio)
46{ 46{
47 struct bio_vec *bv; 47 struct bio_vec *bv;
48 int i; 48 int i;
49 49
50 bio_for_each_segment_all(bv, bio, i) { 50 bio_for_each_segment_all(bv, bio, i) {
51 struct page *page = bv->bv_page; 51 struct page *page = bv->bv_page;
52 page_endio(page, bio_data_dir(bio), err); 52 page_endio(page, bio_data_dir(bio), bio->bi_error);
53 } 53 }
54 54
55 bio_put(bio); 55 bio_put(bio);
diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
index d2554fe140a3..9cd4eb3a1e22 100644
--- a/fs/nfs/blocklayout/blocklayout.c
+++ b/fs/nfs/blocklayout/blocklayout.c
@@ -116,7 +116,7 @@ bl_submit_bio(int rw, struct bio *bio)
116 116
117static struct bio * 117static struct bio *
118bl_alloc_init_bio(int npg, struct block_device *bdev, sector_t disk_sector, 118bl_alloc_init_bio(int npg, struct block_device *bdev, sector_t disk_sector,
119 void (*end_io)(struct bio *, int err), struct parallel_io *par) 119 bio_end_io_t end_io, struct parallel_io *par)
120{ 120{
121 struct bio *bio; 121 struct bio *bio;
122 122
@@ -139,8 +139,7 @@ bl_alloc_init_bio(int npg, struct block_device *bdev, sector_t disk_sector,
139static struct bio * 139static struct bio *
140do_add_page_to_bio(struct bio *bio, int npg, int rw, sector_t isect, 140do_add_page_to_bio(struct bio *bio, int npg, int rw, sector_t isect,
141 struct page *page, struct pnfs_block_dev_map *map, 141 struct page *page, struct pnfs_block_dev_map *map,
142 struct pnfs_block_extent *be, 142 struct pnfs_block_extent *be, bio_end_io_t end_io,
143 void (*end_io)(struct bio *, int err),
144 struct parallel_io *par, unsigned int offset, int *len) 143 struct parallel_io *par, unsigned int offset, int *len)
145{ 144{
146 struct pnfs_block_dev *dev = 145 struct pnfs_block_dev *dev =
@@ -183,11 +182,11 @@ retry:
183 return bio; 182 return bio;
184} 183}
185 184
186static void bl_end_io_read(struct bio *bio, int err) 185static void bl_end_io_read(struct bio *bio)
187{ 186{
188 struct parallel_io *par = bio->bi_private; 187 struct parallel_io *par = bio->bi_private;
189 188
190 if (err) { 189 if (bio->bi_error) {
191 struct nfs_pgio_header *header = par->data; 190 struct nfs_pgio_header *header = par->data;
192 191
193 if (!header->pnfs_error) 192 if (!header->pnfs_error)
@@ -316,13 +315,12 @@ out:
316 return PNFS_ATTEMPTED; 315 return PNFS_ATTEMPTED;
317} 316}
318 317
319static void bl_end_io_write(struct bio *bio, int err) 318static void bl_end_io_write(struct bio *bio)
320{ 319{
321 struct parallel_io *par = bio->bi_private; 320 struct parallel_io *par = bio->bi_private;
322 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
323 struct nfs_pgio_header *header = par->data; 321 struct nfs_pgio_header *header = par->data;
324 322
325 if (!uptodate) { 323 if (bio->bi_error) {
326 if (!header->pnfs_error) 324 if (!header->pnfs_error)
327 header->pnfs_error = -EIO; 325 header->pnfs_error = -EIO;
328 pnfs_set_lo_fail(header->lseg); 326 pnfs_set_lo_fail(header->lseg);
diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c
index 42468e5ab3e7..550b10efb14e 100644
--- a/fs/nilfs2/segbuf.c
+++ b/fs/nilfs2/segbuf.c
@@ -338,12 +338,11 @@ void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed)
338/* 338/*
339 * BIO operations 339 * BIO operations
340 */ 340 */
341static void nilfs_end_bio_write(struct bio *bio, int err) 341static void nilfs_end_bio_write(struct bio *bio)
342{ 342{
343 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
344 struct nilfs_segment_buffer *segbuf = bio->bi_private; 343 struct nilfs_segment_buffer *segbuf = bio->bi_private;
345 344
346 if (!uptodate) 345 if (bio->bi_error)
347 atomic_inc(&segbuf->sb_err); 346 atomic_inc(&segbuf->sb_err);
348 347
349 bio_put(bio); 348 bio_put(bio);
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 16eff45727ee..140de3c93d2e 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -372,14 +372,13 @@ static void o2hb_wait_on_io(struct o2hb_region *reg,
372 wait_for_completion(&wc->wc_io_complete); 372 wait_for_completion(&wc->wc_io_complete);
373} 373}
374 374
375static void o2hb_bio_end_io(struct bio *bio, 375static void o2hb_bio_end_io(struct bio *bio)
376 int error)
377{ 376{
378 struct o2hb_bio_wait_ctxt *wc = bio->bi_private; 377 struct o2hb_bio_wait_ctxt *wc = bio->bi_private;
379 378
380 if (error) { 379 if (bio->bi_error) {
381 mlog(ML_ERROR, "IO Error %d\n", error); 380 mlog(ML_ERROR, "IO Error %d\n", bio->bi_error);
382 wc->wc_error = error; 381 wc->wc_error = bio->bi_error;
383 } 382 }
384 383
385 o2hb_bio_wait_dec(wc, 1); 384 o2hb_bio_wait_dec(wc, 1);
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 3859f5e27a4d..3714844a81d8 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -351,12 +351,11 @@ xfs_imap_valid(
351 */ 351 */
352STATIC void 352STATIC void
353xfs_end_bio( 353xfs_end_bio(
354 struct bio *bio, 354 struct bio *bio)
355 int error)
356{ 355{
357 xfs_ioend_t *ioend = bio->bi_private; 356 xfs_ioend_t *ioend = bio->bi_private;
358 357
359 ioend->io_error = test_bit(BIO_UPTODATE, &bio->bi_flags) ? 0 : error; 358 ioend->io_error = bio->bi_error;
360 359
361 /* Toss bio and pass work off to an xfsdatad thread */ 360 /* Toss bio and pass work off to an xfsdatad thread */
362 bio->bi_private = NULL; 361 bio->bi_private = NULL;
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index a4b7d92e946c..01bd6781974e 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -1096,8 +1096,7 @@ xfs_bwrite(
1096 1096
1097STATIC void 1097STATIC void
1098xfs_buf_bio_end_io( 1098xfs_buf_bio_end_io(
1099 struct bio *bio, 1099 struct bio *bio)
1100 int error)
1101{ 1100{
1102 xfs_buf_t *bp = (xfs_buf_t *)bio->bi_private; 1101 xfs_buf_t *bp = (xfs_buf_t *)bio->bi_private;
1103 1102
@@ -1105,10 +1104,10 @@ xfs_buf_bio_end_io(
1105 * don't overwrite existing errors - otherwise we can lose errors on 1104 * don't overwrite existing errors - otherwise we can lose errors on
1106 * buffers that require multiple bios to complete. 1105 * buffers that require multiple bios to complete.
1107 */ 1106 */
1108 if (error) { 1107 if (bio->bi_error) {
1109 spin_lock(&bp->b_lock); 1108 spin_lock(&bp->b_lock);
1110 if (!bp->b_io_error) 1109 if (!bp->b_io_error)
1111 bp->b_io_error = error; 1110 bp->b_io_error = bio->bi_error;
1112 spin_unlock(&bp->b_lock); 1111 spin_unlock(&bp->b_lock);
1113 } 1112 }
1114 1113