Skip to content

Commit

Permalink
block: submit_bio_wait() conversions
Browse files Browse the repository at this point in the history
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]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Kent Overstreet authored and axboe committed Nov 24, 2013
1 parent 2c57502 commit c170bbb
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 116 deletions.
19 changes: 1 addition & 18 deletions block/blk-flush.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,6 @@ void blk_abort_flushes(struct request_queue *q)
}
}

static void bio_end_flush(struct bio *bio, int err)
{
if (err)
clear_bit(BIO_UPTODATE, &bio->bi_flags);
if (bio->bi_private)
complete(bio->bi_private);
bio_put(bio);
}

/**
* blkdev_issue_flush - queue a flush
* @bdev: blockdev to issue flush for
Expand All @@ -526,7 +517,6 @@ static void bio_end_flush(struct bio *bio, int err)
int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
sector_t *error_sector)
{
DECLARE_COMPLETION_ONSTACK(wait);
struct request_queue *q;
struct bio *bio;
int ret = 0;
Expand All @@ -548,13 +538,9 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
return -ENXIO;

bio = bio_alloc(gfp_mask, 0);
bio->bi_end_io = bio_end_flush;
bio->bi_bdev = bdev;
bio->bi_private = &wait;

bio_get(bio);
submit_bio(WRITE_FLUSH, bio);
wait_for_completion_io(&wait);
ret = submit_bio_wait(WRITE_FLUSH, bio);

/*
* The driver must store the error location in ->bi_sector, if
Expand All @@ -564,9 +550,6 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
if (error_sector)
*error_sector = bio->bi_sector;

if (!bio_flagged(bio, BIO_UPTODATE))
ret = -EIO;

bio_put(bio);
return ret;
}
Expand Down
12 changes: 1 addition & 11 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,16 +776,10 @@ void md_super_wait(struct mddev *mddev)
finish_wait(&mddev->sb_wait, &wq);
}

static void bi_complete(struct bio *bio, int error)
{
complete((struct completion*)bio->bi_private);
}

int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
struct page *page, int rw, bool metadata_op)
{
struct bio *bio = bio_alloc_mddev(GFP_NOIO, 1, rdev->mddev);
struct completion event;
int ret;

rw |= REQ_SYNC;
Expand All @@ -801,11 +795,7 @@ int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
else
bio->bi_sector = sector + rdev->data_offset;
bio_add_page(bio, page, size, 0);
init_completion(&event);
bio->bi_private = &event;
bio->bi_end_io = bi_complete;
submit_bio(rw, bio);
wait_for_completion(&event);
submit_bio_wait(rw, bio);

ret = test_bit(BIO_UPTODATE, &bio->bi_flags);
bio_put(bio);
Expand Down
32 changes: 13 additions & 19 deletions fs/btrfs/check-integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ static void btrfsic_release_block_ctx(struct btrfsic_block_data_ctx *block_ctx);
static int btrfsic_read_block(struct btrfsic_state *state,
struct btrfsic_block_data_ctx *block_ctx);
static void btrfsic_dump_database(struct btrfsic_state *state);
static void btrfsic_complete_bio_end_io(struct bio *bio, int err);
static int btrfsic_test_for_metadata(struct btrfsic_state *state,
char **datav, unsigned int num_pages);
static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
Expand Down Expand Up @@ -1677,7 +1676,6 @@ static int btrfsic_read_block(struct btrfsic_state *state,
for (i = 0; i < num_pages;) {
struct bio *bio;
unsigned int j;
DECLARE_COMPLETION_ONSTACK(complete);

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

for (j = i; j < num_pages; j++) {
ret = bio_add_page(bio, block_ctx->pagev[j],
Expand All @@ -1702,12 +1698,7 @@ static int btrfsic_read_block(struct btrfsic_state *state,
"btrfsic: error, failed to add a single page!\n");
return -1;
}
submit_bio(READ, bio);

/* this will also unplug the queue */
wait_for_completion(&complete);

if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) {
if (submit_bio_wait(READ, bio)) {
printk(KERN_INFO
"btrfsic: read error at logical %llu dev %s!\n",
block_ctx->start, block_ctx->dev->name);
Expand All @@ -1730,11 +1721,6 @@ static int btrfsic_read_block(struct btrfsic_state *state,
return block_ctx->len;
}

static void btrfsic_complete_bio_end_io(struct bio *bio, int err)
{
complete((struct completion *)bio->bi_private);
}

static void btrfsic_dump_database(struct btrfsic_state *state)
{
struct list_head *elem_all;
Expand Down Expand Up @@ -2998,14 +2984,12 @@ int btrfsic_submit_bh(int rw, struct buffer_head *bh)
return submit_bh(rw, bh);
}

void btrfsic_submit_bio(int rw, struct bio *bio)
static void __btrfsic_submit_bio(int rw, struct bio *bio)
{
struct btrfsic_dev_state *dev_state;

if (!btrfsic_is_initialized) {
submit_bio(rw, bio);
if (!btrfsic_is_initialized)
return;
}

mutex_lock(&btrfsic_mutex);
/* since btrfsic_submit_bio() is also called before
Expand Down Expand Up @@ -3097,10 +3081,20 @@ void btrfsic_submit_bio(int rw, struct bio *bio)
}
leave:
mutex_unlock(&btrfsic_mutex);
}

void btrfsic_submit_bio(int rw, struct bio *bio)
{
__btrfsic_submit_bio(rw, bio);
submit_bio(rw, bio);
}

int btrfsic_submit_bio_wait(int rw, struct bio *bio)
{
__btrfsic_submit_bio(rw, bio);
return submit_bio_wait(rw, bio);
}

int btrfsic_mount(struct btrfs_root *root,
struct btrfs_fs_devices *fs_devices,
int including_extent_data, u32 print_mask)
Expand Down
2 changes: 2 additions & 0 deletions fs/btrfs/check-integrity.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
int btrfsic_submit_bh(int rw, struct buffer_head *bh);
void btrfsic_submit_bio(int rw, struct bio *bio);
int btrfsic_submit_bio_wait(int rw, struct bio *bio);
#else
#define btrfsic_submit_bh submit_bh
#define btrfsic_submit_bio submit_bio
#define btrfsic_submit_bio_wait submit_bio_wait
#endif

int btrfsic_mount(struct btrfs_root *root,
Expand Down
12 changes: 1 addition & 11 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1952,11 +1952,6 @@ static int free_io_failure(struct inode *inode, struct io_failure_record *rec,
return err;
}

static void repair_io_failure_callback(struct bio *bio, int err)
{
complete(bio->bi_private);
}

/*
* this bypasses the standard btrfs submit functions deliberately, as
* the standard behavior is to write all copies in a raid setup. here we only
Expand All @@ -1973,7 +1968,6 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
{
struct bio *bio;
struct btrfs_device *dev;
DECLARE_COMPLETION_ONSTACK(compl);
u64 map_length = 0;
u64 sector;
struct btrfs_bio *bbio = NULL;
Expand All @@ -1989,8 +1983,6 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 start,
bio = btrfs_io_bio_alloc(GFP_NOFS, 1);
if (!bio)
return -EIO;
bio->bi_private = &compl;
bio->bi_end_io = repair_io_failure_callback;
bio->bi_size = 0;
map_length = length;

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

if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) {
if (btrfsic_submit_bio_wait(WRITE_SYNC, bio)) {
/* try to remap that extent elsewhere? */
bio_put(bio);
btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);
Expand Down
33 changes: 4 additions & 29 deletions fs/btrfs/scrub.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info,
int is_metadata, int have_csum,
const u8 *csum, u64 generation,
u16 csum_size);
static void scrub_complete_bio_end_io(struct bio *bio, int err);
static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad,
struct scrub_block *sblock_good,
int force_write);
Expand Down Expand Up @@ -1292,7 +1291,6 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
for (page_num = 0; page_num < sblock->page_count; page_num++) {
struct bio *bio;
struct scrub_page *page = sblock->pagev[page_num];
DECLARE_COMPLETION_ONSTACK(complete);

if (page->dev->bdev == NULL) {
page->io_error = 1;
Expand All @@ -1309,18 +1307,11 @@ static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
}
bio->bi_bdev = page->dev->bdev;
bio->bi_sector = page->physical >> 9;
bio->bi_end_io = scrub_complete_bio_end_io;
bio->bi_private = &complete;

bio_add_page(bio, page->page, PAGE_SIZE, 0);
btrfsic_submit_bio(READ, bio);

/* this will also unplug the queue */
wait_for_completion(&complete);

page->io_error = !test_bit(BIO_UPTODATE, &bio->bi_flags);
if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
if (btrfsic_submit_bio_wait(READ, bio))
sblock->no_io_error_seen = 0;

bio_put(bio);
}

Expand Down Expand Up @@ -1389,11 +1380,6 @@ static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info,
sblock->checksum_error = 1;
}

static void scrub_complete_bio_end_io(struct bio *bio, int err)
{
complete((struct completion *)bio->bi_private);
}

static int scrub_repair_block_from_good_copy(struct scrub_block *sblock_bad,
struct scrub_block *sblock_good,
int force_write)
Expand Down Expand Up @@ -1428,7 +1414,6 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
sblock_bad->checksum_error || page_bad->io_error) {
struct bio *bio;
int ret;
DECLARE_COMPLETION_ONSTACK(complete);

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

ret = bio_add_page(bio, page_good->page, PAGE_SIZE, 0);
if (PAGE_SIZE != ret) {
bio_put(bio);
return -EIO;
}
btrfsic_submit_bio(WRITE, bio);

/* this will also unplug the queue */
wait_for_completion(&complete);
if (!bio_flagged(bio, BIO_UPTODATE)) {
if (btrfsic_submit_bio_wait(WRITE, bio)) {
btrfs_dev_stat_inc_and_print(page_bad->dev,
BTRFS_DEV_STAT_WRITE_ERRS);
btrfs_dev_replace_stats_inc(
Expand Down Expand Up @@ -3373,7 +3353,6 @@ static int write_page_nocow(struct scrub_ctx *sctx,
struct bio *bio;
struct btrfs_device *dev;
int ret;
DECLARE_COMPLETION_ONSTACK(compl);

dev = sctx->wr_ctx.tgtdev;
if (!dev)
Expand All @@ -3390,8 +3369,6 @@ static int write_page_nocow(struct scrub_ctx *sctx,
spin_unlock(&sctx->stat_lock);
return -ENOMEM;
}
bio->bi_private = &compl;
bio->bi_end_io = scrub_complete_bio_end_io;
bio->bi_size = 0;
bio->bi_sector = physical_for_dev_replace >> 9;
bio->bi_bdev = dev->bdev;
Expand All @@ -3402,10 +3379,8 @@ static int write_page_nocow(struct scrub_ctx *sctx,
btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);
return -EIO;
}
btrfsic_submit_bio(WRITE_SYNC, bio);
wait_for_completion(&compl);

if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
if (btrfsic_submit_bio_wait(WRITE_SYNC, bio))
goto leave_with_eio;

bio_put(bio);
Expand Down
17 changes: 1 addition & 16 deletions fs/hfsplus/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ struct hfsplus_wd {
u16 embed_count;
};

static void hfsplus_end_io_sync(struct bio *bio, int err)
{
if (err)
clear_bit(BIO_UPTODATE, &bio->bi_flags);
complete(bio->bi_private);
}

/*
* hfsplus_submit_bio - Perfrom block I/O
* @sb: super block of volume for I/O
Expand All @@ -53,7 +46,6 @@ static void hfsplus_end_io_sync(struct bio *bio, int err)
int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
void *buf, void **data, int rw)
{
DECLARE_COMPLETION_ONSTACK(wait);
struct bio *bio;
int ret = 0;
u64 io_size;
Expand All @@ -73,8 +65,6 @@ int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
bio = bio_alloc(GFP_NOIO, 1);
bio->bi_sector = sector;
bio->bi_bdev = sb->s_bdev;
bio->bi_end_io = hfsplus_end_io_sync;
bio->bi_private = &wait;

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

submit_bio(rw, bio);
wait_for_completion(&wait);

if (!bio_flagged(bio, BIO_UPTODATE))
ret = -EIO;

ret = submit_bio_wait(rw, bio);
out:
bio_put(bio);
return ret < 0 ? ret : 0;
Expand Down
Loading

0 comments on commit c170bbb

Please sign in to comment.