Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <jbacik@fusionio.com>

+11 -1
+11 -1
fs/btrfs/disk-io.c
··· 2986 2986 if (wait) { 2987 2987 bh = __find_get_block(device->bdev, bytenr / 4096, 2988 2988 BTRFS_SUPER_INFO_SIZE); 2989 - BUG_ON(!bh); 2989 + if (!bh) { 2990 + errors++; 2991 + continue; 2992 + } 2990 2993 wait_on_buffer(bh); 2991 2994 if (!buffer_uptodate(bh)) 2992 2995 errors++; ··· 3016 3013 */ 3017 3014 bh = __getblk(device->bdev, bytenr / 4096, 3018 3015 BTRFS_SUPER_INFO_SIZE); 3016 + if (!bh) { 3017 + printk(KERN_ERR "btrfs: couldn't get super " 3018 + "buffer head for bytenr %Lu\n", bytenr); 3019 + errors++; 3020 + continue; 3021 + } 3022 + 3019 3023 memcpy(bh->b_data, sb, BTRFS_SUPER_INFO_SIZE); 3020 3024 3021 3025 /* one reference for submit_bh */