Skip to content

Commit 33879d4

Browse files
author
Kent Overstreet
committed
block: submit_bio_wait() conversions
It was being open coded in a few places. Signed-off-by: Kent Overstreet <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Joern Engel <[email protected]> Cc: Prasad Joshi <[email protected]> Cc: Neil Brown <[email protected]> Cc: Chris Mason <[email protected]> Acked-by: NeilBrown <[email protected]>
1 parent 6ce4eac commit 33879d4

File tree

8 files changed

+24
-118
lines changed

8 files changed

+24
-118
lines changed

block/blk-flush.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -502,15 +502,6 @@ void blk_abort_flushes(struct request_queue *q)
502502
}
503503
}
504504

505-
static 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-
514505
/**
515506
* blkdev_issue_flush - queue a flush
516507
* @bdev: blockdev to issue flush for
@@ -526,7 +517,6 @@ static void bio_end_flush(struct bio *bio, int err)
526517
int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
527518
sector_t *error_sector)
528519
{
529-
DECLARE_COMPLETION_ONSTACK(wait);
530520
struct request_queue *q;
531521
struct bio *bio;
532522
int ret = 0;
@@ -548,13 +538,9 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
548538
return -ENXIO;
549539

550540
bio = bio_alloc(gfp_mask, 0);
551-
bio->bi_end_io = bio_end_flush;
552541
bio->bi_bdev = bdev;
553-
bio->bi_private = &wait;
554542

555-
bio_get(bio);
556-
submit_bio(WRITE_FLUSH, bio);
557-
wait_for_completion_io(&wait);
543+
ret = submit_bio_wait(WRITE_FLUSH, bio);
558544

559545
/*
560546
* 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,
564550
if (error_sector)
565551
*error_sector = bio->bi_sector;
566552

567-
if (!bio_flagged(bio, BIO_UPTODATE))
568-
ret = -EIO;
569-
570553
bio_put(bio);
571554
return ret;
572555
}

drivers/md/md.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -776,20 +776,12 @@ void md_super_wait(struct mddev *mddev)
776776
finish_wait(&mddev->sb_wait, &wq);
777777
}
778778

779-
static void bi_complete(struct bio *bio, int error)
780-
{
781-
complete((struct completion*)bio->bi_private);
782-
}
783-
784779
int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
785780
struct page *page, int rw, bool metadata_op)
786781
{
787782
struct bio *bio = bio_alloc_mddev(GFP_NOIO, 1, rdev->mddev);
788-
struct completion event;
789783
int ret;
790784

791-
rw |= REQ_SYNC;
792-
793785
bio->bi_bdev = (metadata_op && rdev->meta_bdev) ?
794786
rdev->meta_bdev : rdev->bdev;
795787
if (metadata_op)
@@ -801,11 +793,7 @@ int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
801793
else
802794
bio->bi_sector = sector + rdev->data_offset;
803795
bio_add_page(bio, page, size, 0);
804-
init_completion(&event);
805-
bio->bi_private = &event;
806-
bio->bi_end_io = bi_complete;
807-
submit_bio(rw, bio);
808-
wait_for_completion(&event);
796+
submit_bio_wait(rw, bio);
809797

810798
ret = test_bit(BIO_UPTODATE, &bio->bi_flags);
811799
bio_put(bio);

fs/btrfs/check-integrity.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ static void btrfsic_release_block_ctx(struct btrfsic_block_data_ctx *block_ctx);
333333
static int btrfsic_read_block(struct btrfsic_state *state,
334334
struct btrfsic_block_data_ctx *block_ctx);
335335
static void btrfsic_dump_database(struct btrfsic_state *state);
336-
static void btrfsic_complete_bio_end_io(struct bio *bio, int err);
337336
static int btrfsic_test_for_metadata(struct btrfsic_state *state,
338337
char **datav, unsigned int num_pages);
339338
static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
@@ -1687,7 +1686,6 @@ static int btrfsic_read_block(struct btrfsic_state *state,
16871686
for (i = 0; i < num_pages;) {
16881687
struct bio *bio;
16891688
unsigned int j;
1690-
DECLARE_COMPLETION_ONSTACK(complete);
16911689

16921690
bio = btrfs_io_bio_alloc(GFP_NOFS, num_pages - i);
16931691
if (!bio) {
@@ -1698,8 +1696,6 @@ static int btrfsic_read_block(struct btrfsic_state *state,
16981696
}
16991697
bio->bi_bdev = block_ctx->dev->bdev;
17001698
bio->bi_sector = dev_bytenr >> 9;
1701-
bio->bi_end_io = btrfsic_complete_bio_end_io;
1702-
bio->bi_private = &complete;
17031699

17041700
for (j = i; j < num_pages; j++) {
17051701
ret = bio_add_page(bio, block_ctx->pagev[j],
@@ -1712,12 +1708,7 @@ static int btrfsic_read_block(struct btrfsic_state *state,
17121708
"btrfsic: error, failed to add a single page!\n");
17131709
return -1;
17141710
}
1715-
submit_bio(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)) {
1711+
if (submit_bio_wait(READ, bio)) {
17211712
printk(KERN_INFO
17221713
"btrfsic: read error at logical %llu dev %s!\n",
17231714
block_ctx->start, block_ctx->dev->name);
@@ -1740,11 +1731,6 @@ static int btrfsic_read_block(struct btrfsic_state *state,
17401731
return block_ctx->len;
17411732
}
17421733

1743-
static void btrfsic_complete_bio_end_io(struct bio *bio, int err)
1744-
{
1745-
complete((struct completion *)bio->bi_private);
1746-
}
1747-
17481734
static void btrfsic_dump_database(struct btrfsic_state *state)
17491735
{
17501736
struct list_head *elem_all;
@@ -3008,14 +2994,12 @@ int btrfsic_submit_bh(int rw, struct buffer_head *bh)
30082994
return submit_bh(rw, bh);
30092995
}
30102996

3011-
void btrfsic_submit_bio(int rw, struct bio *bio)
2997+
static void __btrfsic_submit_bio(int rw, struct bio *bio)
30122998
{
30132999
struct btrfsic_dev_state *dev_state;
30143000

3015-
if (!btrfsic_is_initialized) {
3016-
submit_bio(rw, bio);
3001+
if (!btrfsic_is_initialized)
30173002
return;
3018-
}
30193003

30203004
mutex_lock(&btrfsic_mutex);
30213005
/* since btrfsic_submit_bio() is also called before
@@ -3106,10 +3090,20 @@ void btrfsic_submit_bio(int rw, struct bio *bio)
31063090
}
31073091
leave:
31083092
mutex_unlock(&btrfsic_mutex);
3093+
}
31093094

3095+
void btrfsic_submit_bio(int rw, struct bio *bio)
3096+
{
3097+
__btrfsic_submit_bio(rw, bio);
31103098
submit_bio(rw, bio);
31113099
}
31123100

3101+
int 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+
31133107
int btrfsic_mount(struct btrfs_root *root,
31143108
struct btrfs_fs_devices *fs_devices,
31153109
int including_extent_data, u32 print_mask)

fs/btrfs/check-integrity.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
2323
int btrfsic_submit_bh(int rw, struct buffer_head *bh);
2424
void btrfsic_submit_bio(int rw, struct bio *bio);
25+
int btrfsic_submit_bio_wait(int rw, struct bio *bio);
2526
#else
2627
#define btrfsic_submit_bh submit_bh
2728
#define btrfsic_submit_bio submit_bio
29+
#define btrfsic_submit_bio_wait submit_bio_wait
2830
#endif
2931

3032
int btrfsic_mount(struct btrfs_root *root,

fs/btrfs/extent_io.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,11 +1952,6 @@ static int free_io_failure(struct inode *inode, struct io_failure_record *rec,
19521952
return err;
19531953
}
19541954

1955-
static void repair_io_failure_callback(struct bio *bio, int err)
1956-
{
1957-
complete(bio->bi_private);
1958-
}
1959-
19601955
/*
19611956
* this bypasses the standard btrfs submit functions deliberately, as
19621957
* 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,
19731968
{
19741969
struct bio *bio;
19751970
struct btrfs_device *dev;
1976-
DECLARE_COMPLETION_ONSTACK(compl);
19771971
u64 map_length = 0;
19781972
u64 sector;
19791973
struct btrfs_bio *bbio = NULL;
@@ -1990,8 +1984,6 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
19901984
bio = btrfs_io_bio_alloc(GFP_NOFS, 1);
19911985
if (!bio)
19921986
return -EIO;
1993-
bio->bi_private = &compl;
1994-
bio->bi_end_io = repair_io_failure_callback;
19951987
bio->bi_size = 0;
19961988
map_length = length;
19971989

@@ -2012,10 +2004,8 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
20122004
}
20132005
bio->bi_bdev = dev->bdev;
20142006
bio_add_page(bio, page, length, start - page_offset(page));
2015-
btrfsic_submit_bio(WRITE_SYNC, bio);
2016-
wait_for_completion(&compl);
20172007

2018-
if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) {
2008+
if (btrfsic_submit_bio_wait(WRITE_SYNC, bio)) {
20192009
/* try to remap that extent elsewhere? */
20202010
bio_put(bio);
20212011
btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);

fs/btrfs/scrub.c

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info,
208208
int is_metadata, int have_csum,
209209
const u8 *csum, u64 generation,
210210
u16 csum_size);
211-
static void scrub_complete_bio_end_io(struct bio *bio, int err);
212211
static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad,
213212
struct scrub_block *sblock_good,
214213
int force_write);
@@ -1294,7 +1293,6 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
12941293
for (page_num = 0; page_num < sblock->page_count; page_num++) {
12951294
struct bio *bio;
12961295
struct scrub_page *page = sblock->pagev[page_num];
1297-
DECLARE_COMPLETION_ONSTACK(complete);
12981296

12991297
if (page->dev->bdev == NULL) {
13001298
page->io_error = 1;
@@ -1311,18 +1309,11 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
13111309
}
13121310
bio->bi_bdev = page->dev->bdev;
13131311
bio->bi_sector = page->physical >> 9;
1314-
bio->bi_end_io = scrub_complete_bio_end_io;
1315-
bio->bi_private = &complete;
13161312

13171313
bio_add_page(bio, page->page, PAGE_SIZE, 0);
1318-
btrfsic_submit_bio(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))
1314+
if (btrfsic_submit_bio_wait(READ, bio))
13251315
sblock->no_io_error_seen = 0;
1316+
13261317
bio_put(bio);
13271318
}
13281319

@@ -1391,11 +1382,6 @@ static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info,
13911382
sblock->checksum_error = 1;
13921383
}
13931384

1394-
static void scrub_complete_bio_end_io(struct bio *bio, int err)
1395-
{
1396-
complete((struct completion *)bio->bi_private);
1397-
}
1398-
13991385
static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad,
14001386
struct scrub_block *sblock_good,
14011387
int force_write)
@@ -1430,7 +1416,6 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
14301416
sblock_bad->checksum_error || page_bad->io_error) {
14311417
struct bio *bio;
14321418
int ret;
1433-
DECLARE_COMPLETION_ONSTACK(complete);
14341419

14351420
if (!page_bad->dev->bdev) {
14361421
printk_ratelimited(KERN_WARNING
@@ -1443,19 +1428,14 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
14431428
return -EIO;
14441429
bio->bi_bdev = page_bad->dev->bdev;
14451430
bio->bi_sector = page_bad->physical >> 9;
1446-
bio->bi_end_io = scrub_complete_bio_end_io;
1447-
bio->bi_private = &complete;
14481431

14491432
ret = bio_add_page(bio, page_good->page, PAGE_SIZE, 0);
14501433
if (PAGE_SIZE != ret) {
14511434
bio_put(bio);
14521435
return -EIO;
14531436
}
1454-
btrfsic_submit_bio(WRITE, bio);
14551437

1456-
/* this will also unplug the queue */
1457-
wait_for_completion(&complete);
1458-
if (!bio_flagged(bio, BIO_UPTODATE)) {
1438+
if (btrfsic_submit_bio_wait(WRITE, bio)) {
14591439
btrfs_dev_stat_inc_and_print(page_bad->dev,
14601440
BTRFS_DEV_STAT_WRITE_ERRS);
14611441
btrfs_dev_replace_stats_inc(
@@ -3375,7 +3355,6 @@ static int write_page_nocow(struct scrub_ctx *sctx,
33753355
struct bio *bio;
33763356
struct btrfs_device *dev;
33773357
int ret;
3378-
DECLARE_COMPLETION_ONSTACK(compl);
33793358

33803359
dev = sctx->wr_ctx.tgtdev;
33813360
if (!dev)
@@ -3392,8 +3371,6 @@ static int write_page_nocow(struct scrub_ctx *sctx,
33923371
spin_unlock(&sctx->stat_lock);
33933372
return -ENOMEM;
33943373
}
3395-
bio->bi_private = &compl;
3396-
bio->bi_end_io = scrub_complete_bio_end_io;
33973374
bio->bi_size = 0;
33983375
bio->bi_sector = physical_for_dev_replace >> 9;
33993376
bio->bi_bdev = dev->bdev;
@@ -3404,10 +3381,8 @@ static int write_page_nocow(struct scrub_ctx *sctx,
34043381
btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);
34053382
return -EIO;
34063383
}
3407-
btrfsic_submit_bio(WRITE_SYNC, bio);
3408-
wait_for_completion(&compl);
34093384

3410-
if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
3385+
if (btrfsic_submit_bio_wait(WRITE_SYNC, bio))
34113386
goto leave_with_eio;
34123387

34133388
bio_put(bio);

fs/hfsplus/wrapper.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ struct hfsplus_wd {
2424
u16 embed_count;
2525
};
2626

27-
static 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-
3427
/*
3528
* hfsplus_submit_bio - Perfrom block I/O
3629
* @sb: super block of volume for I/O
@@ -53,7 +46,6 @@ static void hfsplus_end_io_sync(struct bio *bio, int err)
5346
int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
5447
void *buf, void **data, int rw)
5548
{
56-
DECLARE_COMPLETION_ONSTACK(wait);
5749
struct bio *bio;
5850
int ret = 0;
5951
u64 io_size;
@@ -73,8 +65,6 @@ int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
7365
bio = bio_alloc(GFP_NOIO, 1);
7466
bio->bi_sector = sector;
7567
bio->bi_bdev = sb->s_bdev;
76-
bio->bi_end_io = hfsplus_end_io_sync;
77-
bio->bi_private = &wait;
7868

7969
if (!(rw & WRITE) && data)
8070
*data = (u8 *)buf + offset;
@@ -93,12 +83,7 @@ int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
9383
buf = (u8 *)buf + len;
9484
}
9585

96-
submit_bio(rw, bio);
97-
wait_for_completion(&wait);
98-
99-
if (!bio_flagged(bio, BIO_UPTODATE))
100-
ret = -EIO;
101-
86+
ret = submit_bio_wait(rw, bio);
10287
out:
10388
bio_put(bio);
10489
return ret < 0 ? ret : 0;

0 commit comments

Comments
 (0)