btrfs: Record error in btree_csum_one_bio()
PATCH 1/1 btrfs: Record error in btree_csum_one_bio()
Since commit 6dc4f100c175 ("block: allow bio_for_each_segment_all() to iterate over multi-page bvec"), break will only break the inner loop of bio_for_each_segment_all(), unable to break the outer loop.
So here we add a new variable @err to record the first error we hit, and return the error, so that write time checker can work as designed.
--- fs/btrfs/disk-io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/disk-io.c +4 -4
@@ -832,18 +832,18 @@ static blk_status_t btree_csum_one_bio(struct bio *bio) {struct bio_vec *bvec;struct btrfs_root *root; -int i, ret =0 ; +int i, ret =0 , err =0 ;struct bvec_iter_all iter_all;ASSERT (!bio_flagged (bio,BIO_CLONED ));bio_for_each_segment_all (bvec, bio, i, iter_all) { root =BTRFS_I (bvec->bv_page->mapping->host)->root; ret =csum_dirty_buffer (root->fs_info, bvec->bv_page); -if (ret) -break ; +if (ret && !err) + err = ret; } -return errno_to_blk_status (ret); +return errno_to_blk_status (err); } static blk_status_t btree_submit_bio_start(void *private_data, struct bio *bio,
Signature · 1 line
2.21.0
Quoted 3 lines · Qu Wenruo
Since commit
6dc4f100c175("block: allowbio_for_each_segment_all()to iterate over multi-page bvec"), break will only break the inner loop ofbio_for_each_segment_all(), unable to break the outer loop.
Breaking of outer loop should be implemented with a goto rather than introducing a new variable.
Quoted 37 lines
So here we add a new variable @err to record the first error we hit, and return the error, so that write time checker can work as designed.
Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/disk-io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)fs/btrfs/disk-io.c +4
-4@@ -832,18 +832,18 @@ static blk_status_t btree_csum_one_bio(struct bio *bio) {struct bio_vec *bvec;struct btrfs_root *root; -int i, ret =0 ; +int i, ret =0 , err =0 ;struct bvec_iter_all iter_all;ASSERT (!bio_flagged (bio,BIO_CLONED ));bio_for_each_segment_all (bvec, bio, i, iter_all) { root =BTRFS_I (bvec->bv_page->mapping->host)->root; ret =csum_dirty_buffer (root->fs_info, bvec->bv_page); -if (ret) -break ; +if (ret && !err) + err = ret; } -return errno_to_blk_status (ret); +return errno_to_blk_status (err); } static blk_status_t btree_submit_bio_start(void *private_data, struct bio *bio,