Btrfs: SB read failure should return EIO for __bread failure
This will return EIO when __bread() fails to read SB, instead of EINVAL. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
c1b7e47459
commit
92fc03fbdc
|
@ -2653,8 +2653,8 @@ int open_ctree(struct super_block *sb,
|
||||||
* Read super block and check the signature bytes only
|
* Read super block and check the signature bytes only
|
||||||
*/
|
*/
|
||||||
bh = btrfs_read_dev_super(fs_devices->latest_bdev);
|
bh = btrfs_read_dev_super(fs_devices->latest_bdev);
|
||||||
if (!bh) {
|
if (IS_ERR(bh)) {
|
||||||
err = -EINVAL;
|
err = PTR_ERR(bh);
|
||||||
goto fail_alloc;
|
goto fail_alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3196,6 +3196,7 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
|
||||||
int i;
|
int i;
|
||||||
u64 transid = 0;
|
u64 transid = 0;
|
||||||
u64 bytenr;
|
u64 bytenr;
|
||||||
|
int ret = -EINVAL;
|
||||||
|
|
||||||
/* we would like to check all the supers, but that would make
|
/* we would like to check all the supers, but that would make
|
||||||
* a btrfs mount succeed after a mkfs from a different FS.
|
* a btrfs mount succeed after a mkfs from a different FS.
|
||||||
|
@ -3209,13 +3210,20 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
|
||||||
break;
|
break;
|
||||||
bh = __bread(bdev, bytenr / 4096,
|
bh = __bread(bdev, bytenr / 4096,
|
||||||
BTRFS_SUPER_INFO_SIZE);
|
BTRFS_SUPER_INFO_SIZE);
|
||||||
if (!bh)
|
/*
|
||||||
|
* If we fail to read from the underlying devices, as of now
|
||||||
|
* the best option we have is to mark it EIO.
|
||||||
|
*/
|
||||||
|
if (!bh) {
|
||||||
|
ret = -EIO;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
super = (struct btrfs_super_block *)bh->b_data;
|
super = (struct btrfs_super_block *)bh->b_data;
|
||||||
if (btrfs_super_bytenr(super) != bytenr ||
|
if (btrfs_super_bytenr(super) != bytenr ||
|
||||||
btrfs_super_magic(super) != BTRFS_MAGIC) {
|
btrfs_super_magic(super) != BTRFS_MAGIC) {
|
||||||
brelse(bh);
|
brelse(bh);
|
||||||
|
ret = -EINVAL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3227,6 +3235,10 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
|
||||||
brelse(bh);
|
brelse(bh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!latest)
|
||||||
|
return ERR_PTR(ret);
|
||||||
|
|
||||||
return latest;
|
return latest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,8 +211,8 @@ btrfs_get_bdev_and_sb(const char *device_path, fmode_t flags, void *holder,
|
||||||
}
|
}
|
||||||
invalidate_bdev(*bdev);
|
invalidate_bdev(*bdev);
|
||||||
*bh = btrfs_read_dev_super(*bdev);
|
*bh = btrfs_read_dev_super(*bdev);
|
||||||
if (!*bh) {
|
if (IS_ERR(*bh)) {
|
||||||
ret = -EINVAL;
|
ret = PTR_ERR(*bh);
|
||||||
blkdev_put(*bdev, flags);
|
blkdev_put(*bdev, flags);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -6746,8 +6746,8 @@ int btrfs_scratch_superblock(struct btrfs_device *device)
|
||||||
struct btrfs_super_block *disk_super;
|
struct btrfs_super_block *disk_super;
|
||||||
|
|
||||||
bh = btrfs_read_dev_super(device->bdev);
|
bh = btrfs_read_dev_super(device->bdev);
|
||||||
if (!bh)
|
if (IS_ERR(bh))
|
||||||
return -EINVAL;
|
return PTR_ERR(bh);
|
||||||
disk_super = (struct btrfs_super_block *)bh->b_data;
|
disk_super = (struct btrfs_super_block *)bh->b_data;
|
||||||
|
|
||||||
memset(&disk_super->magic, 0, sizeof(disk_super->magic));
|
memset(&disk_super->magic, 0, sizeof(disk_super->magic));
|
||||||
|
|
Loading…
Reference in New Issue