Skip to content

Commit 8b110e3

Browse files
Miao XieChris Mason
authored andcommitted
Btrfs: implement repair function when direct read fails
This patch implement data repair function when direct read fails. The detail of the implementation is: - When we find the data is not right, we try to read the data from the other mirror. - When the io on the mirror ends, we will insert the endio work into the dedicated btrfs workqueue, not common read endio workqueue, because the original endio work is still blocked in the btrfs endio workqueue, if we insert the endio work of the io on the mirror into that workqueue, deadlock would happen. - After we get right data, we write it back to the corrupted mirror. - And if the data on the new mirror is still corrupted, we will try next mirror until we read right data or all the mirrors are traversed. - After the above work, we set the uptodate flag according to the result. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent 28e1cc7 commit 8b110e3

9 files changed

Lines changed: 281 additions & 29 deletions

File tree

‎fs/btrfs/async-thread.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ BTRFS_WORK_HELPER(endio_helper);
7474
BTRFS_WORK_HELPER(endio_meta_helper);
7575
BTRFS_WORK_HELPER(endio_meta_write_helper);
7676
BTRFS_WORK_HELPER(endio_raid56_helper);
77+
BTRFS_WORK_HELPER(endio_repair_helper);
7778
BTRFS_WORK_HELPER(rmw_helper);
7879
BTRFS_WORK_HELPER(endio_write_helper);
7980
BTRFS_WORK_HELPER(freespace_write_helper);

‎fs/btrfs/async-thread.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ BTRFS_WORK_HELPER_PROTO(endio_helper);
5353
BTRFS_WORK_HELPER_PROTO(endio_meta_helper);
5454
BTRFS_WORK_HELPER_PROTO(endio_meta_write_helper);
5555
BTRFS_WORK_HELPER_PROTO(endio_raid56_helper);
56+
BTRFS_WORK_HELPER_PROTO(endio_repair_helper);
5657
BTRFS_WORK_HELPER_PROTO(rmw_helper);
5758
BTRFS_WORK_HELPER_PROTO(endio_write_helper);
5859
BTRFS_WORK_HELPER_PROTO(freespace_write_helper);

‎fs/btrfs/btrfs_inode.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ struct btrfs_dio_private {
271271
* The original bio may be splited to several sub-bios, this is
272272
* done during endio of sub-bios
273273
*/
274-
int (*subio_endio)(struct inode *, struct btrfs_io_bio *);
274+
int (*subio_endio)(struct inode *, struct btrfs_io_bio *, int);
275275
};
276276

277277
/*

‎fs/btrfs/ctree.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,7 @@ struct btrfs_fs_info {
15381538
struct btrfs_workqueue *endio_workers;
15391539
struct btrfs_workqueue *endio_meta_workers;
15401540
struct btrfs_workqueue *endio_raid56_workers;
1541+
struct btrfs_workqueue *endio_repair_workers;
15411542
struct btrfs_workqueue *rmw_workers;
15421543
struct btrfs_workqueue *endio_meta_write_workers;
15431544
struct btrfs_workqueue *endio_write_workers;

‎fs/btrfs/disk-io.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,11 @@ static void end_workqueue_bio(struct bio *bio, int err)
713713
func = btrfs_endio_write_helper;
714714
}
715715
} else {
716-
if (end_io_wq->metadata == BTRFS_WQ_ENDIO_RAID56) {
716+
if (unlikely(end_io_wq->metadata ==
717+
BTRFS_WQ_ENDIO_DIO_REPAIR)) {
718+
wq = fs_info->endio_repair_workers;
719+
func = btrfs_endio_repair_helper;
720+
} else if (end_io_wq->metadata == BTRFS_WQ_ENDIO_RAID56) {
717721
wq = fs_info->endio_raid56_workers;
718722
func = btrfs_endio_raid56_helper;
719723
} else if (end_io_wq->metadata) {
@@ -741,6 +745,7 @@ int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio,
741745
int metadata)
742746
{
743747
struct end_io_wq *end_io_wq;
748+
744749
end_io_wq = kmalloc(sizeof(*end_io_wq), GFP_NOFS);
745750
if (!end_io_wq)
746751
return -ENOMEM;
@@ -2055,6 +2060,7 @@ static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info)
20552060
btrfs_destroy_workqueue(fs_info->endio_workers);
20562061
btrfs_destroy_workqueue(fs_info->endio_meta_workers);
20572062
btrfs_destroy_workqueue(fs_info->endio_raid56_workers);
2063+
btrfs_destroy_workqueue(fs_info->endio_repair_workers);
20582064
btrfs_destroy_workqueue(fs_info->rmw_workers);
20592065
btrfs_destroy_workqueue(fs_info->endio_meta_write_workers);
20602066
btrfs_destroy_workqueue(fs_info->endio_write_workers);
@@ -2572,6 +2578,8 @@ int open_ctree(struct super_block *sb,
25722578
btrfs_alloc_workqueue("endio-meta-write", flags, max_active, 2);
25732579
fs_info->endio_raid56_workers =
25742580
btrfs_alloc_workqueue("endio-raid56", flags, max_active, 4);
2581+
fs_info->endio_repair_workers =
2582+
btrfs_alloc_workqueue("endio-repair", flags, 1, 0);
25752583
fs_info->rmw_workers =
25762584
btrfs_alloc_workqueue("rmw", flags, max_active, 2);
25772585
fs_info->endio_write_workers =
@@ -2593,6 +2601,7 @@ int open_ctree(struct super_block *sb,
25932601
fs_info->submit_workers && fs_info->flush_workers &&
25942602
fs_info->endio_workers && fs_info->endio_meta_workers &&
25952603
fs_info->endio_meta_write_workers &&
2604+
fs_info->endio_repair_workers &&
25962605
fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
25972606
fs_info->endio_freespace_worker && fs_info->rmw_workers &&
25982607
fs_info->caching_workers && fs_info->readahead_workers &&

‎fs/btrfs/disk-io.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum {
3030
BTRFS_WQ_ENDIO_METADATA = 1,
3131
BTRFS_WQ_ENDIO_FREE_SPACE = 2,
3232
BTRFS_WQ_ENDIO_RAID56 = 3,
33+
BTRFS_WQ_ENDIO_DIO_REPAIR = 4,
3334
};
3435

3536
static inline u64 btrfs_sb_offset(int mirror)

‎fs/btrfs/extent_io.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,7 @@ static void check_page_uptodate(struct extent_io_tree *tree, struct page *page)
19621962
SetPageUptodate(page);
19631963
}
19641964

1965-
static int free_io_failure(struct inode *inode, struct io_failure_record *rec)
1965+
int free_io_failure(struct inode *inode, struct io_failure_record *rec)
19661966
{
19671967
int ret;
19681968
int err = 0;
@@ -2081,8 +2081,8 @@ int repair_eb_io_failure(struct btrfs_root *root, struct extent_buffer *eb,
20812081
* each time an IO finishes, we do a fast check in the IO failure tree
20822082
* to see if we need to process or clean up an io_failure_record
20832083
*/
2084-
static int clean_io_failure(struct inode *inode, u64 start,
2085-
struct page *page, unsigned int pg_offset)
2084+
int clean_io_failure(struct inode *inode, u64 start, struct page *page,
2085+
unsigned int pg_offset)
20862086
{
20872087
u64 private;
20882088
u64 private_failure;
@@ -2291,7 +2291,7 @@ int btrfs_check_repairable(struct inode *inode, struct bio *failed_bio,
22912291
struct bio *btrfs_create_repair_bio(struct inode *inode, struct bio *failed_bio,
22922292
struct io_failure_record *failrec,
22932293
struct page *page, int pg_offset, int icsum,
2294-
bio_end_io_t *endio_func)
2294+
bio_end_io_t *endio_func, void *data)
22952295
{
22962296
struct bio *bio;
22972297
struct btrfs_io_bio *btrfs_failed_bio;
@@ -2305,6 +2305,7 @@ struct bio *btrfs_create_repair_bio(struct inode *inode, struct bio *failed_bio,
23052305
bio->bi_iter.bi_sector = failrec->logical >> 9;
23062306
bio->bi_bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev;
23072307
bio->bi_iter.bi_size = 0;
2308+
bio->bi_private = data;
23082309

23092310
btrfs_failed_bio = btrfs_io_bio(failed_bio);
23102311
if (btrfs_failed_bio->csum) {
@@ -2362,7 +2363,8 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset,
23622363
phy_offset >>= inode->i_sb->s_blocksize_bits;
23632364
bio = btrfs_create_repair_bio(inode, failed_bio, failrec, page,
23642365
start - page_offset(page),
2365-
(int)phy_offset, failed_bio->bi_end_io);
2366+
(int)phy_offset, failed_bio->bi_end_io,
2367+
NULL);
23662368
if (!bio) {
23672369
free_io_failure(inode, failrec);
23682370
return -EIO;

‎fs/btrfs/extent_io.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ struct btrfs_fs_info;
341341
int repair_io_failure(struct inode *inode, u64 start, u64 length, u64 logical,
342342
struct page *page, unsigned int pg_offset,
343343
int mirror_num);
344+
int clean_io_failure(struct inode *inode, u64 start, struct page *page,
345+
unsigned int pg_offset);
344346
int end_extent_writepage(struct page *page, int err, u64 start, u64 end);
345347
int repair_eb_io_failure(struct btrfs_root *root, struct extent_buffer *eb,
346348
int mirror_num);
@@ -371,7 +373,8 @@ int btrfs_check_repairable(struct inode *inode, struct bio *failed_bio,
371373
struct bio *btrfs_create_repair_bio(struct inode *inode, struct bio *failed_bio,
372374
struct io_failure_record *failrec,
373375
struct page *page, int pg_offset, int icsum,
374-
bio_end_io_t *endio_func);
376+
bio_end_io_t *endio_func, void *data);
377+
int free_io_failure(struct inode *inode, struct io_failure_record *rec);
375378
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
376379
noinline u64 find_lock_delalloc_range(struct inode *inode,
377380
struct extent_io_tree *tree,

0 commit comments

Comments
 (0)