Skip to content

Commit ea9947b

Browse files
Stefan Behrenschrismason-xx
authored andcommitted
Btrfs: fix crash in scrub repair code when device is missing
Fix that when scrub tries to repair an I/O or checksum error and one of the devices containing the mirror is missing, it crashes in bio_add_page because the bdev is a NULL pointer for missing devices. Reported-by: Marco L. Crociani <[email protected]> Signed-off-by: Stefan Behrens <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent d04b1de commit ea9947b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/btrfs/scrub.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ static int scrub_setup_recheck_block(struct scrub_dev *sdev,
998998
page = sblock->pagev + page_index;
999999
page->logical = logical;
10001000
page->physical = bbio->stripes[mirror_index].physical;
1001+
/* for missing devices, bdev is NULL */
10011002
page->bdev = bbio->stripes[mirror_index].dev->bdev;
10021003
page->mirror_num = mirror_index + 1;
10031004
page->page = alloc_page(GFP_NOFS);
@@ -1042,6 +1043,12 @@ static int scrub_recheck_block(struct btrfs_fs_info *fs_info,
10421043
struct scrub_page *page = sblock->pagev + page_num;
10431044
DECLARE_COMPLETION_ONSTACK(complete);
10441045

1046+
if (page->bdev == NULL) {
1047+
page->io_error = 1;
1048+
sblock->no_io_error_seen = 0;
1049+
continue;
1050+
}
1051+
10451052
BUG_ON(!page->page);
10461053
bio = bio_alloc(GFP_NOFS, 1);
10471054
if (!bio)

0 commit comments

Comments
 (0)