mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-05 02:19:51 +00: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
1 changed files with 23 additions and 24 deletions
|
@ -1251,49 +1251,48 @@ void btrfs_release_disk_super(struct btrfs_super_block *super)
|
||||||
put_page(page);
|
put_page(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int btrfs_read_disk_super(struct block_device *bdev, u64 bytenr,
|
static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev,
|
||||||
struct page **page,
|
u64 bytenr)
|
||||||
struct btrfs_super_block **disk_super)
|
|
||||||
{
|
{
|
||||||
|
struct btrfs_super_block *disk_super;
|
||||||
|
struct page *page;
|
||||||
void *p;
|
void *p;
|
||||||
pgoff_t index;
|
pgoff_t index;
|
||||||
|
|
||||||
/* make sure our super fits in the device */
|
/* make sure our super fits in the device */
|
||||||
if (bytenr + PAGE_SIZE >= i_size_read(bdev->bd_inode))
|
if (bytenr + PAGE_SIZE >= i_size_read(bdev->bd_inode))
|
||||||
return 1;
|
return ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
/* make sure our super fits in the page */
|
/* make sure our super fits in the page */
|
||||||
if (sizeof(**disk_super) > PAGE_SIZE)
|
if (sizeof(*disk_super) > PAGE_SIZE)
|
||||||
return 1;
|
return ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
/* make sure our super doesn't straddle pages on disk */
|
/* make sure our super doesn't straddle pages on disk */
|
||||||
index = bytenr >> PAGE_SHIFT;
|
index = bytenr >> PAGE_SHIFT;
|
||||||
if ((bytenr + sizeof(**disk_super) - 1) >> PAGE_SHIFT != index)
|
if ((bytenr + sizeof(*disk_super) - 1) >> PAGE_SHIFT != index)
|
||||||
return 1;
|
return ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
/* pull in the page with our super */
|
/* pull in the page with our super */
|
||||||
*page = read_cache_page_gfp(bdev->bd_inode->i_mapping,
|
page = read_cache_page_gfp(bdev->bd_inode->i_mapping, index, GFP_KERNEL);
|
||||||
index, GFP_KERNEL);
|
|
||||||
|
|
||||||
if (IS_ERR(*page))
|
if (IS_ERR(page))
|
||||||
return 1;
|
return ERR_CAST(page);
|
||||||
|
|
||||||
p = page_address(*page);
|
p = page_address(page);
|
||||||
|
|
||||||
/* align our pointer to the offset of the super block */
|
/* 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 ||
|
if (btrfs_super_bytenr(disk_super) != bytenr ||
|
||||||
btrfs_super_magic(*disk_super) != BTRFS_MAGIC) {
|
btrfs_super_magic(disk_super) != BTRFS_MAGIC) {
|
||||||
btrfs_release_disk_super(p);
|
btrfs_release_disk_super(p);
|
||||||
return 1;
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*disk_super)->label[0] &&
|
if (disk_super->label[0] && disk_super->label[BTRFS_LABEL_SIZE - 1])
|
||||||
(*disk_super)->label[BTRFS_LABEL_SIZE - 1])
|
disk_super->label[BTRFS_LABEL_SIZE - 1] = 0;
|
||||||
(*disk_super)->label[BTRFS_LABEL_SIZE - 1] = '\0';
|
|
||||||
|
|
||||||
return 0;
|
return disk_super;
|
||||||
}
|
}
|
||||||
|
|
||||||
int btrfs_forget_devices(const char *path)
|
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;
|
bool new_device_added = false;
|
||||||
struct btrfs_device *device = NULL;
|
struct btrfs_device *device = NULL;
|
||||||
struct block_device *bdev;
|
struct block_device *bdev;
|
||||||
struct page *page;
|
|
||||||
u64 bytenr;
|
u64 bytenr;
|
||||||
|
|
||||||
lockdep_assert_held(&uuid_mutex);
|
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))
|
if (IS_ERR(bdev))
|
||||||
return ERR_CAST(bdev);
|
return ERR_CAST(bdev);
|
||||||
|
|
||||||
if (btrfs_read_disk_super(bdev, bytenr, &page, &disk_super)) {
|
disk_super = btrfs_read_disk_super(bdev, bytenr);
|
||||||
device = ERR_PTR(-EINVAL);
|
if (IS_ERR(disk_super)) {
|
||||||
|
device = ERR_CAST(disk_super);
|
||||||
goto error_bdev_put;
|
goto error_bdev_put;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue