btrfs: not a disk error if the bio_add_page fails
authorAnand Jain <anand.jain@oracle.com>
Fri, 5 Jan 2018 02:47:07 +0000 (10:47 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 26 Mar 2018 13:09:36 +0000 (15:09 +0200)
bio_add_page() can fail for logical reasons as from the bio_add_page()
comments:

/*
 * This will only fail if either bio->bi_vcnt == bio->bi_max_vecs or
 * it's a cloned bio.
 */

Here we have just allocated the bio, so both of those failures can't
occur. So drop the check. We can also drop the error stats for write
error.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/scrub.c

index ec56f33feea9137445e9a1feb092104043ab62dc..beb441d0c5c6c02e816d8d5c74bebf8fb5c92c0a 100644 (file)
@@ -4620,7 +4620,6 @@ static int write_page_nocow(struct scrub_ctx *sctx,
 {
        struct bio *bio;
        struct btrfs_device *dev;
 {
        struct bio *bio;
        struct btrfs_device *dev;
-       int ret;
 
        dev = sctx->wr_tgtdev;
        if (!dev)
 
        dev = sctx->wr_tgtdev;
        if (!dev)
@@ -4635,17 +4634,15 @@ static int write_page_nocow(struct scrub_ctx *sctx,
        bio->bi_iter.bi_sector = physical_for_dev_replace >> 9;
        bio_set_dev(bio, dev->bdev);
        bio->bi_opf = REQ_OP_WRITE | REQ_SYNC;
        bio->bi_iter.bi_sector = physical_for_dev_replace >> 9;
        bio_set_dev(bio, dev->bdev);
        bio->bi_opf = REQ_OP_WRITE | REQ_SYNC;
-       ret = bio_add_page(bio, page, PAGE_SIZE, 0);
-       if (ret != PAGE_SIZE) {
-leave_with_eio:
+       /* bio_add_page won't fail on a freshly allocated bio */
+       bio_add_page(bio, page, PAGE_SIZE, 0);
+
+       if (btrfsic_submit_bio_wait(bio)) {
                bio_put(bio);
                btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);
                return -EIO;
        }
 
                bio_put(bio);
                btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);
                return -EIO;
        }
 
-       if (btrfsic_submit_bio_wait(bio))
-               goto leave_with_eio;
-
        bio_put(bio);
        return 0;
 }
        bio_put(bio);
        return 0;
 }