Skip to content

Commit e7b0fda

Browse files
adam900710kdave
authored andcommitted
btrfs: remove io_failure_record::in_validation
The io_failure_record::in_validation was introduced to handle failed bio which cross several sectors. In such case, we still need to verify which sectors are corrupted. But since we've changed the way how we handle corrupted sectors, by only submitting repair for each corrupted sector, there is no need for extra validation any more. This patch will cleanup all io_failure_record::in_validation related code. Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 8079d26 commit e7b0fda

File tree

2 files changed

+21
-101
lines changed

2 files changed

+21
-101
lines changed

fs/btrfs/extent_io.c

Lines changed: 20 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,13 +2381,6 @@ int clean_io_failure(struct btrfs_fs_info *fs_info,
23812381

23822382
BUG_ON(!failrec->this_mirror);
23832383

2384-
if (failrec->in_validation) {
2385-
/* there was no real error, just free the record */
2386-
btrfs_debug(fs_info,
2387-
"clean_io_failure: freeing dummy error at %llu",
2388-
failrec->start);
2389-
goto out;
2390-
}
23912384
if (sb_rdonly(fs_info->sb))
23922385
goto out;
23932386

@@ -2464,9 +2457,8 @@ static struct io_failure_record *btrfs_get_io_failure_record(struct inode *inode
24642457
failrec = get_state_failrec(failure_tree, start);
24652458
if (!IS_ERR(failrec)) {
24662459
btrfs_debug(fs_info,
2467-
"Get IO Failure Record: (found) logical=%llu, start=%llu, len=%llu, validation=%d",
2468-
failrec->logical, failrec->start, failrec->len,
2469-
failrec->in_validation);
2460+
"Get IO Failure Record: (found) logical=%llu, start=%llu, len=%llu",
2461+
failrec->logical, failrec->start, failrec->len);
24702462
/*
24712463
* when data can be on disk more than twice, add to failrec here
24722464
* (e.g. with a list for failed_mirror) to make
@@ -2484,7 +2476,6 @@ static struct io_failure_record *btrfs_get_io_failure_record(struct inode *inode
24842476
failrec->len = sectorsize;
24852477
failrec->this_mirror = 0;
24862478
failrec->bio_flags = 0;
2487-
failrec->in_validation = 0;
24882479

24892480
read_lock(&em_tree->lock);
24902481
em = lookup_extent_mapping(em_tree, start, failrec->len);
@@ -2535,7 +2526,7 @@ static struct io_failure_record *btrfs_get_io_failure_record(struct inode *inode
25352526
return failrec;
25362527
}
25372528

2538-
static bool btrfs_check_repairable(struct inode *inode, bool needs_validation,
2529+
static bool btrfs_check_repairable(struct inode *inode,
25392530
struct io_failure_record *failrec,
25402531
int failed_mirror)
25412532
{
@@ -2555,39 +2546,22 @@ static bool btrfs_check_repairable(struct inode *inode, bool needs_validation,
25552546
return false;
25562547
}
25572548

2549+
/* The failure record should only contain one sector */
2550+
ASSERT(failrec->len == fs_info->sectorsize);
2551+
25582552
/*
2559-
* there are two premises:
2560-
* a) deliver good data to the caller
2561-
* b) correct the bad sectors on disk
2553+
* There are two premises:
2554+
* a) deliver good data to the caller
2555+
* b) correct the bad sectors on disk
2556+
*
2557+
* Since we're only doing repair for one sector, we only need to get
2558+
* a good copy of the failed sector and if we succeed, we have setup
2559+
* everything for repair_io_failure to do the rest for us.
25622560
*/
2563-
if (needs_validation) {
2564-
/*
2565-
* to fulfill b), we need to know the exact failing sectors, as
2566-
* we don't want to rewrite any more than the failed ones. thus,
2567-
* we need separate read requests for the failed bio
2568-
*
2569-
* if the following BUG_ON triggers, our validation request got
2570-
* merged. we need separate requests for our algorithm to work.
2571-
*/
2572-
BUG_ON(failrec->in_validation);
2573-
failrec->in_validation = 1;
2574-
failrec->this_mirror = failed_mirror;
2575-
} else {
2576-
/*
2577-
* we're ready to fulfill a) and b) alongside. get a good copy
2578-
* of the failed sector and if we succeed, we have setup
2579-
* everything for repair_io_failure to do the rest for us.
2580-
*/
2581-
if (failrec->in_validation) {
2582-
BUG_ON(failrec->this_mirror != failed_mirror);
2583-
failrec->in_validation = 0;
2584-
failrec->this_mirror = 0;
2585-
}
2586-
failrec->failed_mirror = failed_mirror;
2561+
failrec->failed_mirror = failed_mirror;
2562+
failrec->this_mirror++;
2563+
if (failrec->this_mirror == failed_mirror)
25872564
failrec->this_mirror++;
2588-
if (failrec->this_mirror == failed_mirror)
2589-
failrec->this_mirror++;
2590-
}
25912565

25922566
if (failrec->this_mirror > num_copies) {
25932567
btrfs_debug(fs_info,
@@ -2599,48 +2573,6 @@ static bool btrfs_check_repairable(struct inode *inode, bool needs_validation,
25992573
return true;
26002574
}
26012575

2602-
static bool btrfs_io_needs_validation(struct inode *inode, struct bio *bio)
2603-
{
2604-
u64 len = 0;
2605-
const u32 blocksize = inode->i_sb->s_blocksize;
2606-
2607-
/*
2608-
* If bi_status is BLK_STS_OK, then this was a checksum error, not an
2609-
* I/O error. In this case, we already know exactly which sector was
2610-
* bad, so we don't need to validate.
2611-
*/
2612-
if (bio->bi_status == BLK_STS_OK)
2613-
return false;
2614-
2615-
/*
2616-
* We need to validate each sector individually if the failed I/O was
2617-
* for multiple sectors.
2618-
*
2619-
* There are a few possible bios that can end up here:
2620-
* 1. A buffered read bio, which is not cloned.
2621-
* 2. A direct I/O read bio, which is cloned.
2622-
* 3. A (buffered or direct) repair bio, which is not cloned.
2623-
*
2624-
* For cloned bios (case 2), we can get the size from
2625-
* btrfs_io_bio->iter; for non-cloned bios (cases 1 and 3), we can get
2626-
* it from the bvecs.
2627-
*/
2628-
if (bio_flagged(bio, BIO_CLONED)) {
2629-
if (btrfs_io_bio(bio)->iter.bi_size > blocksize)
2630-
return true;
2631-
} else {
2632-
struct bio_vec *bvec;
2633-
int i;
2634-
2635-
bio_for_each_bvec_all(bvec, bio, i) {
2636-
len += bvec->bv_len;
2637-
if (len > blocksize)
2638-
return true;
2639-
}
2640-
}
2641-
return false;
2642-
}
2643-
26442576
int btrfs_repair_one_sector(struct inode *inode,
26452577
struct bio *failed_bio, u32 bio_offset,
26462578
struct page *page, unsigned int pgoff,
@@ -2653,7 +2585,6 @@ int btrfs_repair_one_sector(struct inode *inode,
26532585
struct extent_io_tree *failure_tree = &BTRFS_I(inode)->io_failure_tree;
26542586
struct btrfs_io_bio *failed_io_bio = btrfs_io_bio(failed_bio);
26552587
const int icsum = bio_offset >> fs_info->sectorsize_bits;
2656-
bool need_validation;
26572588
struct bio *repair_bio;
26582589
struct btrfs_io_bio *repair_io_bio;
26592590
blk_status_t status;
@@ -2667,25 +2598,15 @@ int btrfs_repair_one_sector(struct inode *inode,
26672598
if (IS_ERR(failrec))
26682599
return PTR_ERR(failrec);
26692600

2670-
/*
2671-
* We will only submit repair for one sector, thus we don't need
2672-
* extra validation anymore.
2673-
*
2674-
* TODO: All those extra validation related code will be cleaned up
2675-
* later.
2676-
*/
2677-
need_validation = false;
2678-
if (!btrfs_check_repairable(inode, need_validation, failrec,
2679-
failed_mirror)) {
2601+
2602+
if (!btrfs_check_repairable(inode, failrec, failed_mirror)) {
26802603
free_io_failure(failure_tree, tree, failrec);
26812604
return -EIO;
26822605
}
26832606

26842607
repair_bio = btrfs_io_bio_alloc(1);
26852608
repair_io_bio = btrfs_io_bio(repair_bio);
26862609
repair_bio->bi_opf = REQ_OP_READ;
2687-
if (need_validation)
2688-
repair_bio->bi_opf |= REQ_FAILFAST_DEV;
26892610
repair_bio->bi_end_io = failed_bio->bi_end_io;
26902611
repair_bio->bi_iter.bi_sector = failrec->logical >> 9;
26912612
repair_bio->bi_private = failed_bio->bi_private;
@@ -2703,8 +2624,8 @@ int btrfs_repair_one_sector(struct inode *inode,
27032624
repair_io_bio->iter = repair_bio->bi_iter;
27042625

27052626
btrfs_debug(btrfs_sb(inode->i_sb),
2706-
"repair read error: submitting new read to mirror %d, in_validation=%d",
2707-
failrec->this_mirror, failrec->in_validation);
2627+
"repair read error: submitting new read to mirror %d",
2628+
failrec->this_mirror);
27082629

27092630
status = submit_bio_hook(inode, repair_bio, failrec->this_mirror,
27102631
failrec->bio_flags);

fs/btrfs/extent_io.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ int btrfs_repair_eb_io_failure(const struct extent_buffer *eb, int mirror_num);
281281
* When IO fails, either with EIO or csum verification fails, we
282282
* try other mirrors that might have a good copy of the data. This
283283
* io_failure_record is used to record state as we go through all the
284-
* mirrors. If another mirror has good data, the page is set up to date
284+
* mirrors. If another mirror has good data, the sector is set up to date
285285
* and things continue. If a good mirror can't be found, the original
286286
* bio end_io callback is called to indicate things have failed.
287287
*/
@@ -293,7 +293,6 @@ struct io_failure_record {
293293
unsigned long bio_flags;
294294
int this_mirror;
295295
int failed_mirror;
296-
int in_validation;
297296
};
298297

299298
int btrfs_repair_one_sector(struct inode *inode,

0 commit comments

Comments
 (0)