Skip to content

Commit

Permalink
Btrfs: fix crash in scrub repair code when device is missing
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Stefan Behrens authored and chrismason-xx committed May 4, 2012
1 parent d04b1de commit ea9947b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fs/btrfs/scrub.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ static int scrub_setup_recheck_block(struct scrub_dev *sdev,
page = sblock->pagev + page_index;
page->logical = logical;
page->physical = bbio->stripes[mirror_index].physical;
/* for missing devices, bdev is NULL */
page->bdev = bbio->stripes[mirror_index].dev->bdev;
page->mirror_num = mirror_index + 1;
page->page = alloc_page(GFP_NOFS);
Expand Down Expand Up @@ -1042,6 +1043,12 @@ static int scrub_recheck_block(struct btrfs_fs_info *fs_info,
struct scrub_page *page = sblock->pagev + page_num;
DECLARE_COMPLETION_ONSTACK(complete);

if (page->bdev == NULL) {
page->io_error = 1;
sblock->no_io_error_seen = 0;
continue;
}

BUG_ON(!page->page);
bio = bio_alloc(GFP_NOFS, 1);
if (!bio)
Expand Down

0 comments on commit ea9947b

Please sign in to comment.