btrfs_end_bio() does two things, firstly it'd check and print errors
from the underlying layers, secondly it'd check whether it's the last
stripe for this IO (e.g. raid1 consists of two stripes for a single IO).

Since I'd like to do retry on write errors before failing write IO,
the above two parts need to be split.

This add a helper __btrfs_end_bio() to do the second part.

Signed-off-by: Liu Bo <bo.li....@oracle.com>
---
 fs/btrfs/volumes.c | 60 +++++++++++++++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 26 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 4835136..853f9ce 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5987,36 +5987,11 @@ static inline void btrfs_end_bbio(struct btrfs_bio 
*bbio, struct bio *bio)
        btrfs_put_bbio(bbio);
 }
 
-static void btrfs_end_bio(struct bio *bio)
+static void __btrfs_end_bio(struct bio *bio)
 {
        struct btrfs_bio *bbio = bio->bi_private;
        int is_orig_bio = 0;
 
-       if (bio->bi_status) {
-               atomic_inc(&bbio->error);
-               if (bio->bi_status == BLK_STS_IOERR ||
-                   bio->bi_status == BLK_STS_TARGET) {
-                       unsigned int stripe_index =
-                               btrfs_io_bio(bio)->stripe_index;
-                       struct btrfs_device *dev;
-
-                       BUG_ON(stripe_index >= bbio->num_stripes);
-                       dev = bbio->stripes[stripe_index].dev;
-                       if (dev->bdev) {
-                               if (bio_op(bio) == REQ_OP_WRITE)
-                                       btrfs_dev_stat_inc(dev,
-                                               BTRFS_DEV_STAT_WRITE_ERRS);
-                               else
-                                       btrfs_dev_stat_inc(dev,
-                                               BTRFS_DEV_STAT_READ_ERRS);
-                               if (bio->bi_opf & REQ_PREFLUSH)
-                                       btrfs_dev_stat_inc(dev,
-                                               BTRFS_DEV_STAT_FLUSH_ERRS);
-                               btrfs_dev_stat_print_on_error(dev);
-                       }
-               }
-       }
-
        if (bio == bbio->orig_bio)
                is_orig_bio = 1;
 
@@ -6048,6 +6023,39 @@ static void btrfs_end_bio(struct bio *bio)
        }
 }
 
+static void btrfs_end_bio(struct bio *bio)
+{
+       struct btrfs_bio *bbio = bio->bi_private;
+       int is_orig_bio = 0;
+
+       if (bio->bi_status) {
+               atomic_inc(&bbio->error);
+               if (bio->bi_status == BLK_STS_IOERR ||
+                   bio->bi_status == BLK_STS_TARGET) {
+                       unsigned int stripe_index =
+                               btrfs_io_bio(bio)->stripe_index;
+                       struct btrfs_device *dev;
+
+                       BUG_ON(stripe_index >= bbio->num_stripes);
+                       dev = bbio->stripes[stripe_index].dev;
+                       if (dev->bdev) {
+                               if (bio_op(bio) == REQ_OP_WRITE)
+                                       btrfs_dev_stat_inc(dev,
+                                               BTRFS_DEV_STAT_WRITE_ERRS);
+                               else
+                                       btrfs_dev_stat_inc(dev,
+                                               BTRFS_DEV_STAT_READ_ERRS);
+                               if (bio->bi_opf & REQ_PREFLUSH)
+                                       btrfs_dev_stat_inc(dev,
+                                               BTRFS_DEV_STAT_FLUSH_ERRS);
+                               btrfs_dev_stat_print_on_error(dev);
+                       }
+               }
+       }
+
+       __btrfs_end_bio(bio);
+}
+
 /*
  * see run_scheduled_bios for a description of why bios are collected for
  * async submit.
-- 
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to