[PATCH v2 6/7] btrfs: make direct io read path to use the new read repair infrastructure

Qu Wenruo
2022-05-25T10:59:52Z

By doing this, we can also remove the function submit_dio_repair_bio().

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/inode.c | 51 +++++++++++++++++-------------------------------
1 file changed, 18 insertions(+), 33 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index dd0882e1b982..26718ec1e07b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -55,6 +55,7 @@
#include "zoned.h"
#include "subpage.h"
#include "inode-item.h"
+#include "read-repair.h"

struct btrfs_iget_args {
u64 ino;
@@ -7863,58 +7864,42 @@ static void btrfs_dio_private_put(struct btrfs_dio_private *dip)
bio_endio(&dip->bio);
}

-static void submit_dio_repair_bio(struct inode *inode, struct bio *bio,
- int mirror_num,
- enum btrfs_compression_type compress_type)
-{
- struct btrfs_dio_private *dip = bio->bi_private;
- struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
-
- BUG_ON(bio_op(bio) == REQ_OP_WRITE);
-
- if (btrfs_bio_wq_end_io(fs_info, bio, BTRFS_WQ_ENDIO_DATA))
- return;
-
- refcount_inc(&dip->refs);
- if (btrfs_map_bio(fs_info, bio, mirror_num))
- refcount_dec(&dip->refs);
-}
-
static blk_status_t btrfs_check_read_dio_bio(struct btrfs_dio_private *dip,
struct btrfs_bio *bbio,
const bool uptodate)
{
struct inode *inode = dip->inode;
struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
- struct extent_io_tree *failure_tree = &BTRFS_I(inode)->io_failure_tree;
- struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
+ struct btrfs_read_repair_ctrl ctrl = {0};
const bool csum = !(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM);
blk_status_t err = BLK_STS_OK;
struct bvec_iter iter;
struct bio_vec bv;
+ int ret;
u32 offset;

btrfs_bio_for_each_sector(fs_info, bv, bbio, iter, offset) {
u64 start = bbio->file_offset + offset;

- if (uptodate &&
- (!csum || !check_data_csum(inode, bbio, offset, bv.bv_page,
- bv.bv_offset, start))) {
- clean_io_failure(fs_info, failure_tree, io_tree, start,
- bv.bv_page, btrfs_ino(BTRFS_I(inode)),
- bv.bv_offset);
- } else {
- int ret;
-
- ret = btrfs_repair_one_sector(inode, &bbio->bio, offset,
- bv.bv_page, bv.bv_offset, start,
- bbio->mirror_num,
- submit_dio_repair_bio);
+ if (!uptodate ||
+ (csum && check_data_csum(inode, bbio, offset, bv.bv_page,
+ bv.bv_offset, start))) {
+ u64 logical = (bbio->iter.bi_sector << SECTOR_SHIFT) +
+ offset;
+ u8 *csum = NULL;
+
+ if (bbio->csum)
+ csum = btrfs_csum_ptr(fs_info, bbio->csum, offset);
+ ret = btrfs_read_repair_add_sector(inode, &ctrl,
+ bv.bv_page, bv.bv_offset, logical,
+ start, csum, bbio->mirror_num, true);
if (ret)
err = errno_to_blk_status(ret);
}
}
-
+ ret = btrfs_read_repair_finish(&ctrl);
+ if (ret)
+ err = errno_to_blk_status(ret);
return err;
}

--
2.36.1