Skip to content

Commit c170bbb

Browse files
Kent Overstreetaxboe
authored andcommitted
block: submit_bio_wait() conversions
It was being open coded in a few places. Signed-off-by: Kent Overstreet <kmo@daterainc.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Joern Engel <joern@logfs.org> Cc: Prasad Joshi <prasadjoshi.linux@gmail.com> Cc: Neil Brown <neilb@suse.de> Cc: Chris Mason <chris.mason@fusionio.com> Acked-by: NeilBrown <neilb@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 2c57502 commit c170bbb

8 files changed

Lines changed: 24 additions & 116 deletions

File tree

‎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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -776,16 +776,10 @@ 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

791785
rw |= REQ_SYNC;
@@ -801,11 +795,7 @@ int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
801795
else
802796
bio->bi_sector = sector + rdev->data_offset;
803797
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);
798+
submit_bio_wait(rw, bio);
809799

810800
ret = test_bit(BIO_UPTODATE, &bio->bi_flags);
811801
bio_put(bio);

‎fs/btrfs/check-integrity.c‎

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ static void btrfsic_release_block_ctx(struct btrfsic_block_data_ctx *block_ctx);
323323
static int btrfsic_read_block(struct btrfsic_state *state,
324324
struct btrfsic_block_data_ctx *block_ctx);
325325
static void btrfsic_dump_database(struct btrfsic_state *state);
326-
static void btrfsic_complete_bio_end_io(struct bio *bio, int err);
327326
static int btrfsic_test_for_metadata(struct btrfsic_state *state,
328327
char **datav, unsigned int num_pages);
329328
static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
@@ -1677,7 +1676,6 @@ static int btrfsic_read_block(struct btrfsic_state *state,
16771676
for (i = 0; i < num_pages;) {
16781677
struct bio *bio;
16791678
unsigned int j;
1680-
DECLARE_COMPLETION_ONSTACK(complete);
16811679

16821680
bio = btrfs_io_bio_alloc(GFP_NOFS, num_pages - i);
16831681
if (!bio) {
@@ -1688,8 +1686,6 @@ static int btrfsic_read_block(struct btrfsic_state *state,
16881686
}
16891687
bio->bi_bdev = block_ctx->dev->bdev;
16901688
bio->bi_sector = dev_bytenr >> 9;
1691-
bio->bi_end_io = btrfsic_complete_bio_end_io;
1692-
bio->bi_private = &complete;
16931689

16941690
for (j = i; j < num_pages; j++) {
16951691
ret = bio_add_page(bio, block_ctx->pagev[j],
@@ -1702,12 +1698,7 @@ static int btrfsic_read_block(struct btrfsic_state *state,
17021698
"btrfsic: error, failed to add a single page!\n");
17031699
return -1;
17041700
}
1705-
submit_bio(READ, bio);
1706-
1707-
/* this will also unplug the queue */
1708-
wait_for_completion(&complete);
1709-
1710-
if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) {
1701+
if (submit_bio_wait(READ, bio)) {
17111702
printk(KERN_INFO
17121703
"btrfsic: read error at logical %llu dev %s!\n",
17131704
block_ctx->start, block_ctx->dev->name);
@@ -1730,11 +1721,6 @@ static int btrfsic_read_block(struct btrfsic_state *state,
17301721
return block_ctx->len;
17311722
}
17321723

1733-
static void btrfsic_complete_bio_end_io(struct bio *bio, int err)
1734-
{
1735-
complete((struct completion *)bio->bi_private);
1736-
}
1737-
17381724
static void btrfsic_dump_database(struct btrfsic_state *state)
17391725
{
17401726
struct list_head *elem_all;
@@ -2998,14 +2984,12 @@ int btrfsic_submit_bh(int rw, struct buffer_head *bh)
29982984
return submit_bh(rw, bh);
29992985
}
30002986

3001-
void btrfsic_submit_bio(int rw, struct bio *bio)
2987+
static void __btrfsic_submit_bio(int rw, struct bio *bio)
30022988
{
30032989
struct btrfsic_dev_state *dev_state;
30042990

3005-
if (!btrfsic_is_initialized) {
3006-
submit_bio(rw, bio);
2991+
if (!btrfsic_is_initialized)
30072992
return;
3008-
}
30092993

30102994
mutex_lock(&btrfsic_mutex);
30112995
/* since btrfsic_submit_bio() is also called before
@@ -3097,10 +3081,20 @@ void btrfsic_submit_bio(int rw, struct bio *bio)
30973081
}
30983082
leave:
30993083
mutex_unlock(&btrfsic_mutex);
3084+
}
31003085

3086+
void btrfsic_submit_bio(int rw, struct bio *bio)
3087+
{
3088+
__btrfsic_submit_bio(rw, bio);
31013089
submit_bio(rw, bio);
31023090
}
31033091

3092+
int btrfsic_submit_bio_wait(int rw, struct bio *bio)
3093+
{
3094+
__btrfsic_submit_bio(rw, bio);
3095+
return submit_bio_wait(rw, bio);
3096+
}
3097+
31043098
int btrfsic_mount(struct btrfs_root *root,
31053099
struct btrfs_fs_devices *fs_devices,
31063100
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;
@@ -1989,8 +1983,6 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
19891983
bio = btrfs_io_bio_alloc(GFP_NOFS, 1);
19901984
if (!bio)
19911985
return -EIO;
1992-
bio->bi_private = &compl;
1993-
bio->bi_end_io = repair_io_failure_callback;
19941986
bio->bi_size = 0;
19951987
map_length = length;
19961988

@@ -2011,10 +2003,8 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
20112003
}
20122004
bio->bi_bdev = dev->bdev;
20132005
bio_add_page(bio, page, length, start - page_offset(page));
2014-
btrfsic_submit_bio(WRITE_SYNC, bio);
2015-
wait_for_completion(&compl);
20162006

2017-
if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) {
2007+
if (btrfsic_submit_bio_wait(WRITE_SYNC, bio)) {
20182008
/* try to remap that extent elsewhere? */
20192009
bio_put(bio);
20202010
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);
@@ -1292,7 +1291,6 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
12921291
for (page_num = 0; page_num < sblock->page_count; page_num++) {
12931292
struct bio *bio;
12941293
struct scrub_page *page = sblock->pagev[page_num];
1295-
DECLARE_COMPLETION_ONSTACK(complete);
12961294

12971295
if (page->dev->bdev == NULL) {
12981296
page->io_error = 1;
@@ -1309,18 +1307,11 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
13091307
}
13101308
bio->bi_bdev = page->dev->bdev;
13111309
bio->bi_sector = page->physical >> 9;
1312-
bio->bi_end_io = scrub_complete_bio_end_io;
1313-
bio->bi_private = &complete;
13141310

13151311
bio_add_page(bio, page->page, PAGE_SIZE, 0);
1316-
btrfsic_submit_bio(READ, bio);
1317-
1318-
/* this will also unplug the queue */
1319-
wait_for_completion(&complete);
1320-
1321-
page->io_error = !test_bit(BIO_UPTODATE, &bio->bi_flags);
1322-
if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
1312+
if (btrfsic_submit_bio_wait(READ, bio))
13231313
sblock->no_io_error_seen = 0;
1314+
13241315
bio_put(bio);
13251316
}
13261317

@@ -1389,11 +1380,6 @@ static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info,
13891380
sblock->checksum_error = 1;
13901381
}
13911382

1392-
static void scrub_complete_bio_end_io(struct bio *bio, int err)
1393-
{
1394-
complete((struct completion *)bio->bi_private);
1395-
}
1396-
13971383
static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad,
13981384
struct scrub_block *sblock_good,
13991385
int force_write)
@@ -1428,7 +1414,6 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
14281414
sblock_bad->checksum_error || page_bad->io_error) {
14291415
struct bio *bio;
14301416
int ret;
1431-
DECLARE_COMPLETION_ONSTACK(complete);
14321417

14331418
if (!page_bad->dev->bdev) {
14341419
printk_ratelimited(KERN_WARNING
@@ -1441,19 +1426,14 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
14411426
return -EIO;
14421427
bio->bi_bdev = page_bad->dev->bdev;
14431428
bio->bi_sector = page_bad->physical >> 9;
1444-
bio->bi_end_io = scrub_complete_bio_end_io;
1445-
bio->bi_private = &complete;
14461429

14471430
ret = bio_add_page(bio, page_good->page, PAGE_SIZE, 0);
14481431
if (PAGE_SIZE != ret) {
14491432
bio_put(bio);
14501433
return -EIO;
14511434
}
1452-
btrfsic_submit_bio(WRITE, bio);
14531435

1454-
/* this will also unplug the queue */
1455-
wait_for_completion(&complete);
1456-
if (!bio_flagged(bio, BIO_UPTODATE)) {
1436+
if (btrfsic_submit_bio_wait(WRITE, bio)) {
14571437
btrfs_dev_stat_inc_and_print(page_bad->dev,
14581438
BTRFS_DEV_STAT_WRITE_ERRS);
14591439
btrfs_dev_replace_stats_inc(
@@ -3373,7 +3353,6 @@ static int write_page_nocow(struct scrub_ctx *sctx,
33733353
struct bio *bio;
33743354
struct btrfs_device *dev;
33753355
int ret;
3376-
DECLARE_COMPLETION_ONSTACK(compl);
33773356

33783357
dev = sctx->wr_ctx.tgtdev;
33793358
if (!dev)
@@ -3390,8 +3369,6 @@ static int write_page_nocow(struct scrub_ctx *sctx,
33903369
spin_unlock(&sctx->stat_lock);
33913370
return -ENOMEM;
33923371
}
3393-
bio->bi_private = &compl;
3394-
bio->bi_end_io = scrub_complete_bio_end_io;
33953372
bio->bi_size = 0;
33963373
bio->bi_sector = physical_for_dev_replace >> 9;
33973374
bio->bi_bdev = dev->bdev;
@@ -3402,10 +3379,8 @@ static int write_page_nocow(struct scrub_ctx *sctx,
34023379
btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);
34033380
return -EIO;
34043381
}
3405-
btrfsic_submit_bio(WRITE_SYNC, bio);
3406-
wait_for_completion(&compl);
34073382

3408-
if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
3383+
if (btrfsic_submit_bio_wait(WRITE_SYNC, bio))
34093384
goto leave_with_eio;
34103385

34113386
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)