Commit 7870d082 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

Btrfs: don't pass the inode through clean_io_failure

Instead pass around the failure tree and the io tree.
Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
Reviewed-by: default avatarChandan Rajendra <chandan@linux.vnet.ibm.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 6ec656bc
...@@ -1939,11 +1939,12 @@ static void check_page_uptodate(struct extent_io_tree *tree, struct page *page) ...@@ -1939,11 +1939,12 @@ static void check_page_uptodate(struct extent_io_tree *tree, struct page *page)
SetPageUptodate(page); SetPageUptodate(page);
} }
int free_io_failure(struct btrfs_inode *inode, struct io_failure_record *rec) int free_io_failure(struct extent_io_tree *failure_tree,
struct extent_io_tree *io_tree,
struct io_failure_record *rec)
{ {
int ret; int ret;
int err = 0; int err = 0;
struct extent_io_tree *failure_tree = &inode->io_failure_tree;
set_state_failrec(failure_tree, rec->start, NULL); set_state_failrec(failure_tree, rec->start, NULL);
ret = clear_extent_bits(failure_tree, rec->start, ret = clear_extent_bits(failure_tree, rec->start,
...@@ -1952,7 +1953,7 @@ int free_io_failure(struct btrfs_inode *inode, struct io_failure_record *rec) ...@@ -1952,7 +1953,7 @@ int free_io_failure(struct btrfs_inode *inode, struct io_failure_record *rec)
if (ret) if (ret)
err = ret; err = ret;
ret = clear_extent_bits(&inode->io_tree, rec->start, ret = clear_extent_bits(io_tree, rec->start,
rec->start + rec->len - 1, rec->start + rec->len - 1,
EXTENT_DAMAGED); EXTENT_DAMAGED);
if (ret && !err) if (ret && !err)
...@@ -2081,24 +2082,24 @@ int repair_eb_io_failure(struct btrfs_fs_info *fs_info, ...@@ -2081,24 +2082,24 @@ int repair_eb_io_failure(struct btrfs_fs_info *fs_info,
* each time an IO finishes, we do a fast check in the IO failure tree * each time an IO finishes, we do a fast check in the IO failure tree
* to see if we need to process or clean up an io_failure_record * to see if we need to process or clean up an io_failure_record
*/ */
int clean_io_failure(struct btrfs_inode *inode, u64 start, struct page *page, int clean_io_failure(struct btrfs_fs_info *fs_info,
unsigned int pg_offset) struct extent_io_tree *failure_tree,
struct extent_io_tree *io_tree, u64 start,
struct page *page, u64 ino, unsigned int pg_offset)
{ {
u64 private; u64 private;
struct io_failure_record *failrec; struct io_failure_record *failrec;
struct btrfs_fs_info *fs_info = inode->root->fs_info;
struct extent_state *state; struct extent_state *state;
int num_copies; int num_copies;
int ret; int ret;
private = 0; private = 0;
ret = count_range_bits(&inode->io_failure_tree, &private, ret = count_range_bits(failure_tree, &private, (u64)-1, 1,
(u64)-1, 1, EXTENT_DIRTY, 0); EXTENT_DIRTY, 0);
if (!ret) if (!ret)
return 0; return 0;
ret = get_state_failrec(&inode->io_failure_tree, start, ret = get_state_failrec(failure_tree, start, &failrec);
&failrec);
if (ret) if (ret)
return 0; return 0;
...@@ -2114,25 +2115,25 @@ int clean_io_failure(struct btrfs_inode *inode, u64 start, struct page *page, ...@@ -2114,25 +2115,25 @@ int clean_io_failure(struct btrfs_inode *inode, u64 start, struct page *page,
if (fs_info->sb->s_flags & MS_RDONLY) if (fs_info->sb->s_flags & MS_RDONLY)
goto out; goto out;
spin_lock(&inode->io_tree.lock); spin_lock(&io_tree->lock);
state = find_first_extent_bit_state(&inode->io_tree, state = find_first_extent_bit_state(io_tree,
failrec->start, failrec->start,
EXTENT_LOCKED); EXTENT_LOCKED);
spin_unlock(&inode->io_tree.lock); spin_unlock(&io_tree->lock);
if (state && state->start <= failrec->start && if (state && state->start <= failrec->start &&
state->end >= failrec->start + failrec->len - 1) { state->end >= failrec->start + failrec->len - 1) {
num_copies = btrfs_num_copies(fs_info, failrec->logical, num_copies = btrfs_num_copies(fs_info, failrec->logical,
failrec->len); failrec->len);
if (num_copies > 1) { if (num_copies > 1) {
repair_io_failure(fs_info, btrfs_ino(inode), start, repair_io_failure(fs_info, ino, start, failrec->len,
failrec->len, failrec->logical, page, failrec->logical, page, pg_offset,
pg_offset, failrec->failed_mirror); failrec->failed_mirror);
} }
} }
out: out:
free_io_failure(inode, failrec); free_io_failure(failure_tree, io_tree, failrec);
return 0; return 0;
} }
...@@ -2373,6 +2374,7 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset, ...@@ -2373,6 +2374,7 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset,
struct io_failure_record *failrec; struct io_failure_record *failrec;
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree; struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
struct extent_io_tree *failure_tree = &BTRFS_I(inode)->io_failure_tree;
struct bio *bio; struct bio *bio;
int read_mode = 0; int read_mode = 0;
int ret; int ret;
...@@ -2385,7 +2387,7 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset, ...@@ -2385,7 +2387,7 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset,
ret = btrfs_check_repairable(inode, failed_bio, failrec, failed_mirror); ret = btrfs_check_repairable(inode, failed_bio, failrec, failed_mirror);
if (!ret) { if (!ret) {
free_io_failure(BTRFS_I(inode), failrec); free_io_failure(failure_tree, tree, failrec);
return -EIO; return -EIO;
} }
...@@ -2398,7 +2400,7 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset, ...@@ -2398,7 +2400,7 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset,
(int)phy_offset, failed_bio->bi_end_io, (int)phy_offset, failed_bio->bi_end_io,
NULL); NULL);
if (!bio) { if (!bio) {
free_io_failure(BTRFS_I(inode), failrec); free_io_failure(failure_tree, tree, failrec);
return -EIO; return -EIO;
} }
bio_set_op_attrs(bio, REQ_OP_READ, read_mode); bio_set_op_attrs(bio, REQ_OP_READ, read_mode);
...@@ -2410,7 +2412,7 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset, ...@@ -2410,7 +2412,7 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset,
ret = tree->ops->submit_bio_hook(tree->private_data, bio, failrec->this_mirror, ret = tree->ops->submit_bio_hook(tree->private_data, bio, failrec->this_mirror,
failrec->bio_flags, 0); failrec->bio_flags, 0);
if (ret) { if (ret) {
free_io_failure(BTRFS_I(inode), failrec); free_io_failure(failure_tree, tree, failrec);
bio_put(bio); bio_put(bio);
} }
...@@ -2514,7 +2516,7 @@ static void end_bio_extent_readpage(struct bio *bio) ...@@ -2514,7 +2516,7 @@ static void end_bio_extent_readpage(struct bio *bio)
struct bio_vec *bvec; struct bio_vec *bvec;
int uptodate = !bio->bi_error; int uptodate = !bio->bi_error;
struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); struct btrfs_io_bio *io_bio = btrfs_io_bio(bio);
struct extent_io_tree *tree; struct extent_io_tree *tree, *failure_tree;
u64 offset = 0; u64 offset = 0;
u64 start; u64 start;
u64 end; u64 end;
...@@ -2535,6 +2537,7 @@ static void end_bio_extent_readpage(struct bio *bio) ...@@ -2535,6 +2537,7 @@ static void end_bio_extent_readpage(struct bio *bio)
(u64)bio->bi_iter.bi_sector, bio->bi_error, (u64)bio->bi_iter.bi_sector, bio->bi_error,
io_bio->mirror_num); io_bio->mirror_num);
tree = &BTRFS_I(inode)->io_tree; tree = &BTRFS_I(inode)->io_tree;
failure_tree = &BTRFS_I(inode)->io_failure_tree;
/* We always issue full-page reads, but if some block /* We always issue full-page reads, but if some block
* in a page fails to read, blk_update_request() will * in a page fails to read, blk_update_request() will
...@@ -2564,8 +2567,10 @@ static void end_bio_extent_readpage(struct bio *bio) ...@@ -2564,8 +2567,10 @@ static void end_bio_extent_readpage(struct bio *bio)
if (ret) if (ret)
uptodate = 0; uptodate = 0;
else else
clean_io_failure(BTRFS_I(inode), start, clean_io_failure(BTRFS_I(inode)->root->fs_info,
page, 0); failure_tree, tree, start,
page,
btrfs_ino(BTRFS_I(inode)), 0);
} }
if (likely(uptodate)) if (likely(uptodate))
......
...@@ -474,8 +474,10 @@ struct btrfs_inode; ...@@ -474,8 +474,10 @@ struct btrfs_inode;
int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
u64 length, u64 logical, struct page *page, u64 length, u64 logical, struct page *page,
unsigned int pg_offset, int mirror_num); unsigned int pg_offset, int mirror_num);
int clean_io_failure(struct btrfs_inode *inode, u64 start, int clean_io_failure(struct btrfs_fs_info *fs_info,
struct page *page, unsigned int pg_offset); struct extent_io_tree *failure_tree,
struct extent_io_tree *io_tree, u64 start,
struct page *page, u64 ino, unsigned int pg_offset);
void end_extent_writepage(struct page *page, int err, u64 start, u64 end); void end_extent_writepage(struct page *page, int err, u64 start, u64 end);
int repair_eb_io_failure(struct btrfs_fs_info *fs_info, int repair_eb_io_failure(struct btrfs_fs_info *fs_info,
struct extent_buffer *eb, int mirror_num); struct extent_buffer *eb, int mirror_num);
...@@ -510,7 +512,9 @@ struct bio *btrfs_create_repair_bio(struct inode *inode, struct bio *failed_bio, ...@@ -510,7 +512,9 @@ struct bio *btrfs_create_repair_bio(struct inode *inode, struct bio *failed_bio,
struct io_failure_record *failrec, struct io_failure_record *failrec,
struct page *page, int pg_offset, int icsum, struct page *page, int pg_offset, int icsum,
bio_end_io_t *endio_func, void *data); bio_end_io_t *endio_func, void *data);
int free_io_failure(struct btrfs_inode *inode, struct io_failure_record *rec); int free_io_failure(struct extent_io_tree *failure_tree,
struct extent_io_tree *io_tree,
struct io_failure_record *rec);
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
noinline u64 find_lock_delalloc_range(struct inode *inode, noinline u64 find_lock_delalloc_range(struct inode *inode,
struct extent_io_tree *tree, struct extent_io_tree *tree,
......
...@@ -7984,6 +7984,8 @@ static int dio_read_error(struct inode *inode, struct bio *failed_bio, ...@@ -7984,6 +7984,8 @@ static int dio_read_error(struct inode *inode, struct bio *failed_bio,
bio_end_io_t *repair_endio, void *repair_arg) bio_end_io_t *repair_endio, void *repair_arg)
{ {
struct io_failure_record *failrec; struct io_failure_record *failrec;
struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
struct extent_io_tree *failure_tree = &BTRFS_I(inode)->io_failure_tree;
struct bio *bio; struct bio *bio;
int isector; int isector;
int read_mode = 0; int read_mode = 0;
...@@ -7998,7 +8000,7 @@ static int dio_read_error(struct inode *inode, struct bio *failed_bio, ...@@ -7998,7 +8000,7 @@ static int dio_read_error(struct inode *inode, struct bio *failed_bio,
ret = btrfs_check_dio_repairable(inode, failed_bio, failrec, ret = btrfs_check_dio_repairable(inode, failed_bio, failrec,
failed_mirror); failed_mirror);
if (!ret) { if (!ret) {
free_io_failure(BTRFS_I(inode), failrec); free_io_failure(failure_tree, io_tree, failrec);
return -EIO; return -EIO;
} }
...@@ -8012,7 +8014,7 @@ static int dio_read_error(struct inode *inode, struct bio *failed_bio, ...@@ -8012,7 +8014,7 @@ static int dio_read_error(struct inode *inode, struct bio *failed_bio,
bio = btrfs_create_repair_bio(inode, failed_bio, failrec, page, bio = btrfs_create_repair_bio(inode, failed_bio, failrec, page,
pgoff, isector, repair_endio, repair_arg); pgoff, isector, repair_endio, repair_arg);
if (!bio) { if (!bio) {
free_io_failure(BTRFS_I(inode), failrec); free_io_failure(failure_tree, io_tree, failrec);
return -EIO; return -EIO;
} }
bio_set_op_attrs(bio, REQ_OP_READ, read_mode); bio_set_op_attrs(bio, REQ_OP_READ, read_mode);
...@@ -8023,7 +8025,7 @@ static int dio_read_error(struct inode *inode, struct bio *failed_bio, ...@@ -8023,7 +8025,7 @@ static int dio_read_error(struct inode *inode, struct bio *failed_bio,
ret = submit_dio_repair_bio(inode, bio, failrec->this_mirror); ret = submit_dio_repair_bio(inode, bio, failrec->this_mirror);
if (ret) { if (ret) {
free_io_failure(BTRFS_I(inode), failrec); free_io_failure(failure_tree, io_tree, failrec);
bio_put(bio); bio_put(bio);
} }
...@@ -8040,19 +8042,24 @@ struct btrfs_retry_complete { ...@@ -8040,19 +8042,24 @@ struct btrfs_retry_complete {
static void btrfs_retry_endio_nocsum(struct bio *bio) static void btrfs_retry_endio_nocsum(struct bio *bio)
{ {
struct btrfs_retry_complete *done = bio->bi_private; struct btrfs_retry_complete *done = bio->bi_private;
struct inode *inode = done->inode;
struct bio_vec *bvec; struct bio_vec *bvec;
struct extent_io_tree *io_tree, *failure_tree;
int i; int i;
if (bio->bi_error) if (bio->bi_error)
goto end; goto end;
ASSERT(bio->bi_vcnt == 1); ASSERT(bio->bi_vcnt == 1);
ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(done->inode)); io_tree = &BTRFS_I(inode)->io_tree;
failure_tree = &BTRFS_I(inode)->io_failure_tree;
ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(inode));
done->uptodate = 1; done->uptodate = 1;
bio_for_each_segment_all(bvec, bio, i) bio_for_each_segment_all(bvec, bio, i)
clean_io_failure(BTRFS_I(done->inode), done->start, clean_io_failure(BTRFS_I(inode)->root->fs_info, failure_tree,
bvec->bv_page, 0); io_tree, done->start, bvec->bv_page,
btrfs_ino(BTRFS_I(inode)), 0);
end: end:
complete(&done->done); complete(&done->done);
bio_put(bio); bio_put(bio);
...@@ -8117,6 +8124,8 @@ static void btrfs_retry_endio(struct bio *bio) ...@@ -8117,6 +8124,8 @@ static void btrfs_retry_endio(struct bio *bio)
{ {
struct btrfs_retry_complete *done = bio->bi_private; struct btrfs_retry_complete *done = bio->bi_private;
struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); struct btrfs_io_bio *io_bio = btrfs_io_bio(bio);
struct extent_io_tree *io_tree, *failure_tree;
struct inode *inode = done->inode;
struct bio_vec *bvec; struct bio_vec *bvec;
int uptodate; int uptodate;
int ret; int ret;
...@@ -8130,13 +8139,19 @@ static void btrfs_retry_endio(struct bio *bio) ...@@ -8130,13 +8139,19 @@ static void btrfs_retry_endio(struct bio *bio)
ASSERT(bio->bi_vcnt == 1); ASSERT(bio->bi_vcnt == 1);
ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(done->inode)); ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(done->inode));
io_tree = &BTRFS_I(inode)->io_tree;
failure_tree = &BTRFS_I(inode)->io_failure_tree;
bio_for_each_segment_all(bvec, bio, i) { bio_for_each_segment_all(bvec, bio, i) {
ret = __readpage_endio_check(done->inode, io_bio, i, ret = __readpage_endio_check(inode, io_bio, i, bvec->bv_page,
bvec->bv_page, bvec->bv_offset, bvec->bv_offset, done->start,
done->start, bvec->bv_len); bvec->bv_len);
if (!ret) if (!ret)
clean_io_failure(BTRFS_I(done->inode), done->start, clean_io_failure(BTRFS_I(inode)->root->fs_info,
bvec->bv_page, bvec->bv_offset); failure_tree, io_tree, done->start,
bvec->bv_page,
btrfs_ino(BTRFS_I(inode)),
bvec->bv_offset);
else else
uptodate = 0; uptodate = 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment