Commit b335eab8 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

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: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent a7571232
...@@ -1251,49 +1251,48 @@ void btrfs_release_disk_super(struct btrfs_super_block *super) ...@@ -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, ...@@ -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, ...@@ -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;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment