Skip to content

Commit 634554d

Browse files
author
Josef Bacik
committed
Btrfs: deal with errors in write_dev_supers
If you try to mount -o loop a restored file system it will panic if the file ends up being smaller than the original disk. This is because we go to try and get a block for a super that may be past the EOF which makes __getblk return NULL for a buffer head when we aren't expecting it to. Fix this by dealing with this case and just jacking up the errors count. With this patch we no longer panic when mounting a restored file system loopback. Thanks, Signed-off-by: Josef Bacik <[email protected]>
1 parent 3650860 commit 634554d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

fs/btrfs/disk-io.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2986,7 +2986,10 @@ static int write_dev_supers(struct btrfs_device *device,
29862986
if (wait) {
29872987
bh = __find_get_block(device->bdev, bytenr / 4096,
29882988
BTRFS_SUPER_INFO_SIZE);
2989-
BUG_ON(!bh);
2989+
if (!bh) {
2990+
errors++;
2991+
continue;
2992+
}
29902993
wait_on_buffer(bh);
29912994
if (!buffer_uptodate(bh))
29922995
errors++;
@@ -3013,6 +3016,13 @@ static int write_dev_supers(struct btrfs_device *device,
30133016
*/
30143017
bh = __getblk(device->bdev, bytenr / 4096,
30153018
BTRFS_SUPER_INFO_SIZE);
3019+
if (!bh) {
3020+
printk(KERN_ERR "btrfs: couldn't get super "
3021+
"buffer head for bytenr %Lu\n", bytenr);
3022+
errors++;
3023+
continue;
3024+
}
3025+
30163026
memcpy(bh->b_data, sb, BTRFS_SUPER_INFO_SIZE);
30173027

30183028
/* one reference for submit_bh */

0 commit comments

Comments
 (0)