mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-25 07:20:53 +07:00
btrfs: make btrfs_read_disk_super return struct btrfs_disk_super
Instead of returning both the page and the super block structure, make btrfs_read_disk_super just return a pointer to struct btrfs_disk_super. As a result the function signature is simplified. Also, read_cache_page_gfp can never return NULL so check its return value only for IS_ERR. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
a7571232b2
commit
b335eab890
@ -1251,49 +1251,48 @@ void btrfs_release_disk_super(struct btrfs_super_block *super)
|
||||
put_page(page);
|
||||
}
|
||||
|
||||
static int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr,
|
||||
struct page **page,
|
||||
struct btrfs_super_block **disk_super)
|
||||
static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev,
|
||||
u64 bytenr)
|
||||
{
|
||||
struct btrfs_super_block *disk_super;
|
||||
struct page *page;
|
||||
void *p;
|
||||
pgoff_t index;
|
||||
|
||||
/* make sure our super fits in the device */
|
||||
if (bytenr + PAGE_SIZE >= i_size_read(bdev->bd_inode))
|
||||
return 1;
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
/* make sure our super fits in the page */
|
||||
if (sizeof(**disk_super) > PAGE_SIZE)
|
||||
return 1;
|
||||
if (sizeof(*disk_super) > PAGE_SIZE)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
/* make sure our super doesn't straddle pages on disk */
|
||||
index = bytenr >> PAGE_SHIFT;
|
||||
if ((bytenr + sizeof(**disk_super) - 1) >> PAGE_SHIFT != index)
|
||||
return 1;
|
||||
if ((bytenr + sizeof(*disk_super) - 1) >> PAGE_SHIFT != index)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
/* pull in the page with our super */
|
||||
*page = read_cache_page_gfp(bdev->bd_inode->i_mapping,
|
||||
index, GFP_KERNEL);
|
||||
page = read_cache_page_gfp(bdev->bd_inode->i_mapping, index, GFP_KERNEL);
|
||||
|
||||
if (IS_ERR(*page))
|
||||
return 1;
|
||||
if (IS_ERR(page))
|
||||
return ERR_CAST(page);
|
||||
|
||||
p = page_address(*page);
|
||||
p = page_address(page);
|
||||
|
||||
/* align our pointer to the offset of the super block */
|
||||
*disk_super = p + offset_in_page(bytenr);
|
||||
disk_super = p + offset_in_page(bytenr);
|
||||
|
||||
if (btrfs_super_bytenr(*disk_super) != bytenr ||
|
||||
btrfs_super_magic(*disk_super) != BTRFS_MAGIC) {
|
||||
if (btrfs_super_bytenr(disk_super) != bytenr ||
|
||||
btrfs_super_magic(disk_super) != BTRFS_MAGIC) {
|
||||
btrfs_release_disk_super(p);
|
||||
return 1;
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
if ((*disk_super)->label[0] &&
|
||||
(*disk_super)->label[BTRFS_LABEL_SIZE - 1])
|
||||
(*disk_super)->label[BTRFS_LABEL_SIZE - 1] = '\0';
|
||||
if (disk_super->label[0] && disk_super->label[BTRFS_LABEL_SIZE - 1])
|
||||
disk_super->label[BTRFS_LABEL_SIZE - 1] = 0;
|
||||
|
||||
return 0;
|
||||
return disk_super;
|
||||
}
|
||||
|
||||
int btrfs_forget_devices(const char *path)
|
||||
@ -1319,7 +1318,6 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, fmode_t flags,
|
||||
bool new_device_added = false;
|
||||
struct btrfs_device *device = NULL;
|
||||
struct block_device *bdev;
|
||||
struct page *page;
|
||||
u64 bytenr;
|
||||
|
||||
lockdep_assert_held(&uuid_mutex);
|
||||
@ -1337,8 +1335,9 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, fmode_t flags,
|
||||
if (IS_ERR(bdev))
|
||||
return ERR_CAST(bdev);
|
||||
|
||||
if (btrfs_read_disk_super(bdev, bytenr, &page, &disk_super)) {
|
||||
device = ERR_PTR(-EINVAL);
|
||||
disk_super = btrfs_read_disk_super(bdev, bytenr);
|
||||
if (IS_ERR(disk_super)) {
|
||||
device = ERR_CAST(disk_super);
|
||||
goto error_bdev_put;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user