aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-12-05 18:33:27 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-12-05 18:33:27 -0500
commit5ee540613db504a10e15fafaf4c08cac96aa1823 (patch)
treedc0b348debbb557866285dbee51e29ff3496ffa4
parent29be6345bbaec8502a70c4e2204d5818b48c4e8f (diff)
parent0d11e6aca396e679c07b2dd6af5dc8b7f041fbbd (diff)
Merge branch 'for-linus' of git://git.kernel.dk/linux-block
Pull block layer fixes from Jens Axboe: "A small collection of fixes for the current series. It contains: - A fix for a use-after-free of a request in blk-mq. From Ming Lei - A fix for a blk-mq bug that could attempt to dereference a NULL rq if allocation failed - Two xen-blkfront small fixes - Cleanup of submit_bio_wait() type uses in the kernel, unifying that. From Kent - A fix for 32-bit blkg_rwstat reading. I apologize for this one looking mangled in the shortlog, it's entirely my fault for missing an empty line between the description and body of the text" * 'for-linus' of git://git.kernel.dk/linux-block: blk-mq: fix use-after-free of request blk-mq: fix dereference of rq->mq_ctx if allocation fails block: xen-blkfront: Fix possible NULL ptr dereference xen-blkfront: Silence pfn maybe-uninitialized warning block: submit_bio_wait() conversions Update of blkg_stat and blkg_rwstat may happen in bh context
-rw-r--r--block/blk-cgroup.h8
-rw-r--r--block/blk-flush.c19
-rw-r--r--block/blk-mq.c16
-rw-r--r--drivers/block/xen-blkfront.c7
-rw-r--r--drivers/md/md.c12
-rw-r--r--fs/btrfs/check-integrity.c32
-rw-r--r--fs/btrfs/check-integrity.h2
-rw-r--r--fs/btrfs/extent_io.c12
-rw-r--r--fs/btrfs/scrub.c33
-rw-r--r--fs/hfsplus/wrapper.c17
-rw-r--r--fs/logfs/dev_bdev.c13
11 files changed, 44 insertions, 127 deletions
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
index 1610b22edf09..86154eab9523 100644
--- a/block/blk-cgroup.h
+++ b/block/blk-cgroup.h
@@ -435,9 +435,9 @@ static inline uint64_t blkg_stat_read(struct blkg_stat *stat)
435 uint64_t v; 435 uint64_t v;
436 436
437 do { 437 do {
438 start = u64_stats_fetch_begin(&stat->syncp); 438 start = u64_stats_fetch_begin_bh(&stat->syncp);
439 v = stat->cnt; 439 v = stat->cnt;
440 } while (u64_stats_fetch_retry(&stat->syncp, start)); 440 } while (u64_stats_fetch_retry_bh(&stat->syncp, start));
441 441
442 return v; 442 return v;
443} 443}
@@ -508,9 +508,9 @@ static inline struct blkg_rwstat blkg_rwstat_read(struct blkg_rwstat *rwstat)
508 struct blkg_rwstat tmp; 508 struct blkg_rwstat tmp;
509 509
510 do { 510 do {
511 start = u64_stats_fetch_begin(&rwstat->syncp); 511 start = u64_stats_fetch_begin_bh(&rwstat->syncp);
512 tmp = *rwstat; 512 tmp = *rwstat;
513 } while (u64_stats_fetch_retry(&rwstat->syncp, start)); 513 } while (u64_stats_fetch_retry_bh(&rwstat->syncp, start));
514 514
515 return tmp; 515 return tmp;
516} 516}
diff --git a/block/blk-flush.c b/block/blk-flush.c
index 331e627301ea..fb6f3c0ffa49 100644
--- a/block/blk-flush.c
+++ b/block/blk-flush.c
@@ -502,15 +502,6 @@ void blk_abort_flushes(struct request_queue *q)
502 } 502 }
503} 503}
504 504
505static void bio_end_flush(struct bio *bio, int err)
506{
507 if (err)
508 clear_bit(BIO_UPTODATE, &bio->bi_flags);
509 if (bio->bi_private)
510 complete(bio->bi_private);
511 bio_put(bio);
512}
513
514/** 505/**
515 * blkdev_issue_flush - queue a flush 506 * blkdev_issue_flush - queue a flush
516 * @bdev: blockdev to issue flush for 507 * @bdev: blockdev to issue flush for
@@ -526,7 +517,6 @@ static void bio_end_flush(struct bio *bio, int err)
526int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask, 517int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
527 sector_t *error_sector) 518 sector_t *error_sector)
528{ 519{
529 DECLARE_COMPLETION_ONSTACK(wait);
530 struct request_queue *q; 520 struct request_queue *q;
531 struct bio *bio; 521 struct bio *bio;
532 int ret = 0; 522 int ret = 0;
@@ -548,13 +538,9 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
548 return -ENXIO; 538 return -ENXIO;
549 539
550 bio = bio_alloc(gfp_mask, 0); 540 bio = bio_alloc(gfp_mask, 0);
551 bio->bi_end_io = bio_end_flush;
552 bio->bi_bdev = bdev; 541 bio->bi_bdev = bdev;
553 bio->bi_private = &wait;
554 542
555 bio_get(bio); 543 ret = submit_bio_wait(WRITE_FLUSH, bio);
556 submit_bio(WRITE_FLUSH, bio);
557 wait_for_completion_io(&wait);
558 544
559 /* 545 /*
560 * The driver must store the error location in ->bi_sector, if 546 * The driver must store the error location in ->bi_sector, if
@@ -564,9 +550,6 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
564 if (error_sector) 550 if (error_sector)
565 *error_sector = bio->bi_sector; 551 *error_sector = bio->bi_sector;
566 552
567 if (!bio_flagged(bio, BIO_UPTODATE))
568 ret = -EIO;
569
570 bio_put(bio); 553 bio_put(bio);
571 return ret; 554 return ret;
572} 555}
diff --git a/block/blk-mq.c b/block/blk-mq.c
index cdc629cf075b..c79126e11030 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -202,10 +202,12 @@ static struct request *blk_mq_alloc_request_pinned(struct request_queue *q,
202 if (rq) { 202 if (rq) {
203 blk_mq_rq_ctx_init(q, ctx, rq, rw); 203 blk_mq_rq_ctx_init(q, ctx, rq, rw);
204 break; 204 break;
205 } else if (!(gfp & __GFP_WAIT)) 205 }
206 break;
207 206
208 blk_mq_put_ctx(ctx); 207 blk_mq_put_ctx(ctx);
208 if (!(gfp & __GFP_WAIT))
209 break;
210
209 __blk_mq_run_hw_queue(hctx); 211 __blk_mq_run_hw_queue(hctx);
210 blk_mq_wait_for_tags(hctx->tags); 212 blk_mq_wait_for_tags(hctx->tags);
211 } while (1); 213 } while (1);
@@ -222,7 +224,8 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw,
222 return NULL; 224 return NULL;
223 225
224 rq = blk_mq_alloc_request_pinned(q, rw, gfp, reserved); 226 rq = blk_mq_alloc_request_pinned(q, rw, gfp, reserved);
225 blk_mq_put_ctx(rq->mq_ctx); 227 if (rq)
228 blk_mq_put_ctx(rq->mq_ctx);
226 return rq; 229 return rq;
227} 230}
228 231
@@ -235,7 +238,8 @@ struct request *blk_mq_alloc_reserved_request(struct request_queue *q, int rw,
235 return NULL; 238 return NULL;
236 239
237 rq = blk_mq_alloc_request_pinned(q, rw, gfp, true); 240 rq = blk_mq_alloc_request_pinned(q, rw, gfp, true);
238 blk_mq_put_ctx(rq->mq_ctx); 241 if (rq)
242 blk_mq_put_ctx(rq->mq_ctx);
239 return rq; 243 return rq;
240} 244}
241EXPORT_SYMBOL(blk_mq_alloc_reserved_request); 245EXPORT_SYMBOL(blk_mq_alloc_reserved_request);
@@ -308,12 +312,12 @@ void blk_mq_complete_request(struct request *rq, int error)
308 312
309 blk_account_io_completion(rq, bytes); 313 blk_account_io_completion(rq, bytes);
310 314
315 blk_account_io_done(rq);
316
311 if (rq->end_io) 317 if (rq->end_io)
312 rq->end_io(rq, error); 318 rq->end_io(rq, error);
313 else 319 else
314 blk_mq_free_request(rq); 320 blk_mq_free_request(rq);
315
316 blk_account_io_done(rq);
317} 321}
318 322
319void __blk_mq_end_io(struct request *rq, int error) 323void __blk_mq_end_io(struct request *rq, int error)
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 432db1b59b00..c4a4c9006288 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -489,7 +489,7 @@ static int blkif_queue_request(struct request *req)
489 489
490 if ((ring_req->operation == BLKIF_OP_INDIRECT) && 490 if ((ring_req->operation == BLKIF_OP_INDIRECT) &&
491 (i % SEGS_PER_INDIRECT_FRAME == 0)) { 491 (i % SEGS_PER_INDIRECT_FRAME == 0)) {
492 unsigned long pfn; 492 unsigned long uninitialized_var(pfn);
493 493
494 if (segments) 494 if (segments)
495 kunmap_atomic(segments); 495 kunmap_atomic(segments);
@@ -2011,6 +2011,10 @@ static void blkif_release(struct gendisk *disk, fmode_t mode)
2011 2011
2012 bdev = bdget_disk(disk, 0); 2012 bdev = bdget_disk(disk, 0);
2013 2013
2014 if (!bdev) {
2015 WARN(1, "Block device %s yanked out from us!\n", disk->disk_name);
2016 goto out_mutex;
2017 }
2014 if (bdev->bd_openers) 2018 if (bdev->bd_openers)
2015 goto out; 2019 goto out;
2016 2020
@@ -2041,6 +2045,7 @@ static void blkif_release(struct gendisk *disk, fmode_t mode)
2041 2045
2042out: 2046out:
2043 bdput(bdev); 2047 bdput(bdev);
2048out_mutex:
2044 mutex_unlock(&blkfront_mutex); 2049 mutex_unlock(&blkfront_mutex);
2045} 2050}
2046 2051
diff --git a/drivers/md/md.c b/drivers/md/md.c
index e60cebf3f519..21f4d7ff0da2 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -776,16 +776,10 @@ void md_super_wait(struct mddev *mddev)
776 finish_wait(&mddev->sb_wait, &wq); 776 finish_wait(&mddev->sb_wait, &wq);
777} 777}
778 778
779static void bi_complete(struct bio *bio, int error)
780{
781 complete((struct completion*)bio->bi_private);
782}
783
784int sync_page_io(struct md_rdev *rdev, sector_t sector, int size, 779int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
785 struct page *page, int rw, bool metadata_op) 780 struct page *page, int rw, bool metadata_op)
786{ 781{
787 struct bio *bio = bio_alloc_mddev(GFP_NOIO, 1, rdev->mddev); 782 struct bio *bio = bio_alloc_mddev(GFP_NOIO, 1, rdev->mddev);
788 struct completion event;
789 int ret; 783 int ret;
790 784
791 rw |= REQ_SYNC; 785 rw |= REQ_SYNC;
@@ -801,11 +795,7 @@ int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
801 else 795 else
802 bio->bi_sector = sector + rdev->data_offset; 796 bio->bi_sector = sector + rdev->data_offset;
803 bio_add_page(bio, page, size, 0); 797 bio_add_page(bio, page, size, 0);
804 init_completion(&event); 798 submit_bio_wait(rw, bio);
805 bio->bi_private = &event;
806 bio->bi_end_io = bi_complete;
807 submit_bio(rw, bio);
808 wait_for_completion(&event);
809 799
810 ret = test_bit(BIO_UPTODATE, &bio->bi_flags); 800 ret = test_bit(BIO_UPTODATE, &bio->bi_flags);
811 bio_put(bio); 801 bio_put(bio);
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index b50764bef141..131d82800b3a 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -333,7 +333,6 @@ static void btrfsic_release_block_ctx(struct btrfsic_block_data_ctx *block_ctx);
333static int btrfsic_read_block(struct btrfsic_state *state, 333static int btrfsic_read_block(struct btrfsic_state *state,
334 struct btrfsic_block_data_ctx *block_ctx); 334 struct btrfsic_block_data_ctx *block_ctx);
335static void btrfsic_dump_database(struct btrfsic_state *state); 335static void btrfsic_dump_database(struct btrfsic_state *state);
336static void btrfsic_complete_bio_end_io(struct bio *bio, int err);
337static int btrfsic_test_for_metadata(struct btrfsic_state *state, 336static int btrfsic_test_for_metadata(struct btrfsic_state *state,
338 char **datav, unsigned int num_pages); 337 char **datav, unsigned int num_pages);
339static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state, 338static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
@@ -1687,7 +1686,6 @@ static int btrfsic_read_block(struct btrfsic_state *state,
1687 for (i = 0; i < num_pages;) { 1686 for (i = 0; i < num_pages;) {
1688 struct bio *bio; 1687 struct bio *bio;
1689 unsigned int j; 1688 unsigned int j;
1690 DECLARE_COMPLETION_ONSTACK(complete);
1691 1689
1692 bio = btrfs_io_bio_alloc(GFP_NOFS, num_pages - i); 1690 bio = btrfs_io_bio_alloc(GFP_NOFS, num_pages - i);
1693 if (!bio) { 1691 if (!bio) {
@@ -1698,8 +1696,6 @@ static int btrfsic_read_block(struct btrfsic_state *state,
1698 } 1696 }
1699 bio->bi_bdev = block_ctx->dev->bdev; 1697 bio->bi_bdev = block_ctx->dev->bdev;
1700 bio->bi_sector = dev_bytenr >> 9; 1698 bio->bi_sector = dev_bytenr >> 9;
1701 bio->bi_end_io = btrfsic_complete_bio_end_io;
1702 bio->bi_private = &complete;
1703 1699
1704 for (j = i; j < num_pages; j++) { 1700 for (j = i; j < num_pages; j++) {
1705 ret = bio_add_page(bio, block_ctx->pagev[j], 1701 ret = bio_add_page(bio, block_ctx->pagev[j],
@@ -1712,12 +1708,7 @@ static int btrfsic_read_block(struct btrfsic_state *state,
1712 "btrfsic: error, failed to add a single page!\n"); 1708 "btrfsic: error, failed to add a single page!\n");
1713 return -1; 1709 return -1;
1714 } 1710 }
1715 submit_bio(READ, bio); 1711 if (submit_bio_wait(READ, bio)) {
1716
1717 /* this will also unplug the queue */
1718 wait_for_completion(&complete);
1719
1720 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) {
1721 printk(KERN_INFO 1712 printk(KERN_INFO
1722 "btrfsic: read error at logical %llu dev %s!\n", 1713 "btrfsic: read error at logical %llu dev %s!\n",
1723 block_ctx->start, block_ctx->dev->name); 1714 block_ctx->start, block_ctx->dev->name);
@@ -1740,11 +1731,6 @@ static int btrfsic_read_block(struct btrfsic_state *state,
1740 return block_ctx->len; 1731 return block_ctx->len;
1741} 1732}
1742 1733
1743static void btrfsic_complete_bio_end_io(struct bio *bio, int err)
1744{
1745 complete((struct completion *)bio->bi_private);
1746}
1747
1748static void btrfsic_dump_database(struct btrfsic_state *state) 1734static void btrfsic_dump_database(struct btrfsic_state *state)
1749{ 1735{
1750 struct list_head *elem_all; 1736 struct list_head *elem_all;
@@ -3008,14 +2994,12 @@ int btrfsic_submit_bh(int rw, struct buffer_head *bh)
3008 return submit_bh(rw, bh); 2994 return submit_bh(rw, bh);
3009} 2995}
3010 2996
3011void btrfsic_submit_bio(int rw, struct bio *bio) 2997static void __btrfsic_submit_bio(int rw, struct bio *bio)
3012{ 2998{
3013 struct btrfsic_dev_state *dev_state; 2999 struct btrfsic_dev_state *dev_state;
3014 3000
3015 if (!btrfsic_is_initialized) { 3001 if (!btrfsic_is_initialized)
3016 submit_bio(rw, bio);
3017 return; 3002 return;
3018 }
3019 3003
3020 mutex_lock(&btrfsic_mutex); 3004 mutex_lock(&btrfsic_mutex);
3021 /* since btrfsic_submit_bio() is also called before 3005 /* since btrfsic_submit_bio() is also called before
@@ -3106,10 +3090,20 @@ void btrfsic_submit_bio(int rw, struct bio *bio)
3106 } 3090 }
3107leave: 3091leave:
3108 mutex_unlock(&btrfsic_mutex); 3092 mutex_unlock(&btrfsic_mutex);
3093}
3109 3094
3095void btrfsic_submit_bio(int rw, struct bio *bio)
3096{
3097 __btrfsic_submit_bio(rw, bio);
3110 submit_bio(rw, bio); 3098 submit_bio(rw, bio);
3111} 3099}
3112 3100
3101int btrfsic_submit_bio_wait(int rw, struct bio *bio)
3102{
3103 __btrfsic_submit_bio(rw, bio);
3104 return submit_bio_wait(rw, bio);
3105}
3106
3113int btrfsic_mount(struct btrfs_root *root, 3107int btrfsic_mount(struct btrfs_root *root,
3114 struct btrfs_fs_devices *fs_devices, 3108 struct btrfs_fs_devices *fs_devices,
3115 int including_extent_data, u32 print_mask) 3109 int including_extent_data, u32 print_mask)
diff --git a/fs/btrfs/check-integrity.h b/fs/btrfs/check-integrity.h
index 8b59175cc502..13b8566c97ab 100644
--- a/fs/btrfs/check-integrity.h
+++ b/fs/btrfs/check-integrity.h
@@ -22,9 +22,11 @@
22#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY 22#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
23int btrfsic_submit_bh(int rw, struct buffer_head *bh); 23int btrfsic_submit_bh(int rw, struct buffer_head *bh);
24void btrfsic_submit_bio(int rw, struct bio *bio); 24void btrfsic_submit_bio(int rw, struct bio *bio);
25int btrfsic_submit_bio_wait(int rw, struct bio *bio);
25#else 26#else
26#define btrfsic_submit_bh submit_bh 27#define btrfsic_submit_bh submit_bh
27#define btrfsic_submit_bio submit_bio 28#define btrfsic_submit_bio submit_bio
29#define btrfsic_submit_bio_wait submit_bio_wait
28#endif 30#endif
29 31
30int btrfsic_mount(struct btrfs_root *root, 32int btrfsic_mount(struct btrfs_root *root,
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 8e457fca0a0b..ff43802a7c88 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1952,11 +1952,6 @@ static int free_io_failure(struct inode *inode, struct io_failure_record *rec,
1952 return err; 1952 return err;
1953} 1953}
1954 1954
1955static void repair_io_failure_callback(struct bio *bio, int err)
1956{
1957 complete(bio->bi_private);
1958}
1959
1960/* 1955/*
1961 * this bypasses the standard btrfs submit functions deliberately, as 1956 * this bypasses the standard btrfs submit functions deliberately, as
1962 * the standard behavior is to write all copies in a raid setup. here we only 1957 * the standard behavior is to write all copies in a raid setup. here we only
@@ -1973,7 +1968,6 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
1973{ 1968{
1974 struct bio *bio; 1969 struct bio *bio;
1975 struct btrfs_device *dev; 1970 struct btrfs_device *dev;
1976 DECLARE_COMPLETION_ONSTACK(compl);
1977 u64 map_length = 0; 1971 u64 map_length = 0;
1978 u64 sector; 1972 u64 sector;
1979 struct btrfs_bio *bbio = NULL; 1973 struct btrfs_bio *bbio = NULL;
@@ -1990,8 +1984,6 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
1990 bio = btrfs_io_bio_alloc(GFP_NOFS, 1); 1984 bio = btrfs_io_bio_alloc(GFP_NOFS, 1);
1991 if (!bio) 1985 if (!bio)
1992 return -EIO; 1986 return -EIO;
1993 bio->bi_private = &compl;
1994 bio->bi_end_io = repair_io_failure_callback;
1995 bio->bi_size = 0; 1987 bio->bi_size = 0;
1996 map_length = length; 1988 map_length = length;
1997 1989
@@ -2012,10 +2004,8 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
2012 } 2004 }
2013 bio->bi_bdev = dev->bdev; 2005 bio->bi_bdev = dev->bdev;
2014 bio_add_page(bio, page, length, start - page_offset(page)); 2006 bio_add_page(bio, page, length, start - page_offset(page));
2015 btrfsic_submit_bio(WRITE_SYNC, bio);
2016 wait_for_completion(&compl);
2017 2007
2018 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) { 2008 if (btrfsic_submit_bio_wait(WRITE_SYNC, bio)) {
2019 /* try to remap that extent elsewhere? */ 2009 /* try to remap that extent elsewhere? */
2020 bio_put(bio); 2010 bio_put(bio);
2021 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS); 2011 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 561e2f16ba3e..1fd3f33c330a 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -208,7 +208,6 @@ static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info,
208 int is_metadata, int have_csum, 208 int is_metadata, int have_csum,
209 const u8 *csum, u64 generation, 209 const u8 *csum, u64 generation,
210 u16 csum_size); 210 u16 csum_size);
211static void scrub_complete_bio_end_io(struct bio *bio, int err);
212static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad, 211static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad,
213 struct scrub_block *sblock_good, 212 struct scrub_block *sblock_good,
214 int force_write); 213 int force_write);
@@ -1294,7 +1293,6 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
1294 for (page_num = 0; page_num < sblock->page_count; page_num++) { 1293 for (page_num = 0; page_num < sblock->page_count; page_num++) {
1295 struct bio *bio; 1294 struct bio *bio;
1296 struct scrub_page *page = sblock->pagev[page_num]; 1295 struct scrub_page *page = sblock->pagev[page_num];
1297 DECLARE_COMPLETION_ONSTACK(complete);
1298 1296
1299 if (page->dev->bdev == NULL) { 1297 if (page->dev->bdev == NULL) {
1300 page->io_error = 1; 1298 page->io_error = 1;
@@ -1311,18 +1309,11 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
1311 } 1309 }
1312 bio->bi_bdev = page->dev->bdev; 1310 bio->bi_bdev = page->dev->bdev;
1313 bio->bi_sector = page->physical >> 9; 1311 bio->bi_sector = page->physical >> 9;
1314 bio->bi_end_io = scrub_complete_bio_end_io;
1315 bio->bi_private = &complete;
1316 1312
1317 bio_add_page(bio, page->page, PAGE_SIZE, 0); 1313 bio_add_page(bio, page->page, PAGE_SIZE, 0);
1318 btrfsic_submit_bio(READ, bio); 1314 if (btrfsic_submit_bio_wait(READ, bio))
1319
1320 /* this will also unplug the queue */
1321 wait_for_completion(&complete);
1322
1323 page->io_error = !test_bit(BIO_UPTODATE, &bio->bi_flags);
1324 if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
1325 sblock->no_io_error_seen = 0; 1315 sblock->no_io_error_seen = 0;
1316
1326 bio_put(bio); 1317 bio_put(bio);
1327 } 1318 }
1328 1319
@@ -1391,11 +1382,6 @@ static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info,
1391 sblock->checksum_error = 1; 1382 sblock->checksum_error = 1;
1392} 1383}
1393 1384
1394static void scrub_complete_bio_end_io(struct bio *bio, int err)
1395{
1396 complete((struct completion *)bio->bi_private);
1397}
1398
1399static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad, 1385static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad,
1400 struct scrub_block *sblock_good, 1386 struct scrub_block *sblock_good,
1401 int force_write) 1387 int force_write)
@@ -1430,7 +1416,6 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
1430 sblock_bad->checksum_error || page_bad->io_error) { 1416 sblock_bad->checksum_error || page_bad->io_error) {
1431 struct bio *bio; 1417 struct bio *bio;
1432 int ret; 1418 int ret;
1433 DECLARE_COMPLETION_ONSTACK(complete);
1434 1419
1435 if (!page_bad->dev->bdev) { 1420 if (!page_bad->dev->bdev) {
1436 printk_ratelimited(KERN_WARNING 1421 printk_ratelimited(KERN_WARNING
@@ -1443,19 +1428,14 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
1443 return -EIO; 1428 return -EIO;
1444 bio->bi_bdev = page_bad->dev->bdev; 1429 bio->bi_bdev = page_bad->dev->bdev;
1445 bio->bi_sector = page_bad->physical >> 9; 1430 bio->bi_sector = page_bad->physical >> 9;
1446 bio->bi_end_io = scrub_complete_bio_end_io;
1447 bio->bi_private = &complete;
1448 1431
1449 ret = bio_add_page(bio, page_good->page, PAGE_SIZE, 0); 1432 ret = bio_add_page(bio, page_good->page, PAGE_SIZE, 0);
1450 if (PAGE_SIZE != ret) { 1433 if (PAGE_SIZE != ret) {
1451 bio_put(bio); 1434 bio_put(bio);
1452 return -EIO; 1435 return -EIO;
1453 } 1436 }
1454 btrfsic_submit_bio(WRITE, bio);
1455 1437
1456 /* this will also unplug the queue */ 1438 if (btrfsic_submit_bio_wait(WRITE, bio)) {
1457 wait_for_completion(&complete);
1458 if (!bio_flagged(bio, BIO_UPTODATE)) {
1459 btrfs_dev_stat_inc_and_print(page_bad->dev, 1439 btrfs_dev_stat_inc_and_print(page_bad->dev,
1460 BTRFS_DEV_STAT_WRITE_ERRS); 1440 BTRFS_DEV_STAT_WRITE_ERRS);
1461 btrfs_dev_replace_stats_inc( 1441 btrfs_dev_replace_stats_inc(
@@ -3375,7 +3355,6 @@ static int write_page_nocow(struct scrub_ctx *sctx,
3375 struct bio *bio; 3355 struct bio *bio;
3376 struct btrfs_device *dev; 3356 struct btrfs_device *dev;
3377 int ret; 3357 int ret;
3378 DECLARE_COMPLETION_ONSTACK(compl);
3379 3358
3380 dev = sctx->wr_ctx.tgtdev; 3359 dev = sctx->wr_ctx.tgtdev;
3381 if (!dev) 3360 if (!dev)
@@ -3392,8 +3371,6 @@ static int write_page_nocow(struct scrub_ctx *sctx,
3392 spin_unlock(&sctx->stat_lock); 3371 spin_unlock(&sctx->stat_lock);
3393 return -ENOMEM; 3372 return -ENOMEM;
3394 } 3373 }
3395 bio->bi_private = &compl;
3396 bio->bi_end_io = scrub_complete_bio_end_io;
3397 bio->bi_size = 0; 3374 bio->bi_size = 0;
3398 bio->bi_sector = physical_for_dev_replace >> 9; 3375 bio->bi_sector = physical_for_dev_replace >> 9;
3399 bio->bi_bdev = dev->bdev; 3376 bio->bi_bdev = dev->bdev;
@@ -3404,10 +3381,8 @@ leave_with_eio:
3404 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS); 3381 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);
3405 return -EIO; 3382 return -EIO;
3406 } 3383 }
3407 btrfsic_submit_bio(WRITE_SYNC, bio);
3408 wait_for_completion(&compl);
3409 3384
3410 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) 3385 if (btrfsic_submit_bio_wait(WRITE_SYNC, bio))
3411 goto leave_with_eio; 3386 goto leave_with_eio;
3412 3387
3413 bio_put(bio); 3388 bio_put(bio);
diff --git a/fs/hfsplus/wrapper.c b/fs/hfsplus/wrapper.c
index b51a6079108d..e9a97a0d4314 100644
--- a/fs/hfsplus/wrapper.c
+++ b/fs/hfsplus/wrapper.c
@@ -24,13 +24,6 @@ struct hfsplus_wd {
24 u16 embed_count; 24 u16 embed_count;
25}; 25};
26 26
27static void hfsplus_end_io_sync(struct bio *bio, int err)
28{
29 if (err)
30 clear_bit(BIO_UPTODATE, &bio->bi_flags);
31 complete(bio->bi_private);
32}
33
34/* 27/*
35 * hfsplus_submit_bio - Perfrom block I/O 28 * hfsplus_submit_bio - Perfrom block I/O
36 * @sb: super block of volume for I/O 29 * @sb: super block of volume for I/O
@@ -53,7 +46,6 @@ static void hfsplus_end_io_sync(struct bio *bio, int err)
53int hfsplus_submit_bio(struct super_block *sb, sector_t sector, 46int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
54 void *buf, void **data, int rw) 47 void *buf, void **data, int rw)
55{ 48{
56 DECLARE_COMPLETION_ONSTACK(wait);
57 struct bio *bio; 49 struct bio *bio;
58 int ret = 0; 50 int ret = 0;
59 u64 io_size; 51 u64 io_size;
@@ -73,8 +65,6 @@ int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
73 bio = bio_alloc(GFP_NOIO, 1); 65 bio = bio_alloc(GFP_NOIO, 1);
74 bio->bi_sector = sector; 66 bio->bi_sector = sector;
75 bio->bi_bdev = sb->s_bdev; 67 bio->bi_bdev = sb->s_bdev;
76 bio->bi_end_io = hfsplus_end_io_sync;
77 bio->bi_private = &wait;
78 68
79 if (!(rw & WRITE) && data) 69 if (!(rw & WRITE) && data)
80 *data = (u8 *)buf + offset; 70 *data = (u8 *)buf + offset;
@@ -93,12 +83,7 @@ int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
93 buf = (u8 *)buf + len; 83 buf = (u8 *)buf + len;
94 } 84 }
95 85
96 submit_bio(rw, bio); 86 ret = submit_bio_wait(rw, bio);
97 wait_for_completion(&wait);
98
99 if (!bio_flagged(bio, BIO_UPTODATE))
100 ret = -EIO;
101
102out: 87out:
103 bio_put(bio); 88 bio_put(bio);
104 return ret < 0 ? ret : 0; 89 return ret < 0 ? ret : 0;
diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c
index 550475ca6a0e..0f95f0d0b313 100644
--- a/fs/logfs/dev_bdev.c
+++ b/fs/logfs/dev_bdev.c
@@ -14,16 +14,10 @@
14 14
15#define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1)) 15#define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1))
16 16
17static void request_complete(struct bio *bio, int err)
18{
19 complete((struct completion *)bio->bi_private);
20}
21
22static int sync_request(struct page *page, struct block_device *bdev, int rw) 17static int sync_request(struct page *page, struct block_device *bdev, int rw)
23{ 18{
24 struct bio bio; 19 struct bio bio;
25 struct bio_vec bio_vec; 20 struct bio_vec bio_vec;
26 struct completion complete;
27 21
28 bio_init(&bio); 22 bio_init(&bio);
29 bio.bi_max_vecs = 1; 23 bio.bi_max_vecs = 1;
@@ -35,13 +29,8 @@ static int sync_request(struct page *page, struct block_device *bdev, int rw)
35 bio.bi_size = PAGE_SIZE; 29 bio.bi_size = PAGE_SIZE;
36 bio.bi_bdev = bdev; 30 bio.bi_bdev = bdev;
37 bio.bi_sector = page->index * (PAGE_SIZE >> 9); 31 bio.bi_sector = page->index * (PAGE_SIZE >> 9);
38 init_completion(&complete);
39 bio.bi_private = &complete;
40 bio.bi_end_io = request_complete;
41 32
42 submit_bio(rw, &bio); 33 return submit_bio_wait(rw, &bio);
43 wait_for_completion(&complete);
44 return test_bit(BIO_UPTODATE, &bio.bi_flags) ? 0 : -EIO;
45} 34}
46 35
47static int bdev_readpage(void *_sb, struct page *page) 36static int bdev_readpage(void *_sb, struct page *page)