diff mbox series

[RFC,v4,linux-next,15/19] bcache: prevent direct access of bd_inode

Message ID 20240222124555.2049140-16-yukuai1@huaweicloud.com (mailing list archive)
State New
Headers show
Series fs & block: remove bdev->bd_inode | expand

Commit Message

Yu Kuai Feb. 22, 2024, 12:45 p.m. UTC
From: Yu Kuai <yukuai3@huawei.com>

Now that all bcache stash the file of opened bdev, it's ok to get
mapping from the file.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/md/bcache/super.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Jan Kara March 15, 2024, 3:11 p.m. UTC | #1
On Thu 22-02-24 20:45:51, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> Now that all bcache stash the file of opened bdev, it's ok to get
> mapping from the file.
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  drivers/md/bcache/super.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index 4153c9ddbe0b..ec9efa79d5a8 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -163,15 +163,16 @@ static const char *read_super_common(struct cache_sb *sb,  struct block_device *
>  }
>  
>  
> -static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
> +static const char *read_super(struct cache_sb *sb, struct file *bdev_file,
>  			      struct cache_sb_disk **res)
>  {
>  	const char *err;
> +	struct block_device *bdev = file_bdev(bdev_file);
>  	struct cache_sb_disk *s;
>  	struct page *page;
>  	unsigned int i;
>  
> -	page = read_cache_page_gfp(bdev->bd_inode->i_mapping,
> +	page = read_cache_page_gfp(bdev_file->f_mapping,
>  				   SB_OFFSET >> PAGE_SHIFT, GFP_KERNEL);
>  	if (IS_ERR(page))
>  		return "IO error";
> @@ -2564,7 +2565,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>  	if (set_blocksize(file_bdev(bdev_file), 4096))
>  		goto out_blkdev_put;
>  
> -	err = read_super(sb, file_bdev(bdev_file), &sb_disk);
> +	err = read_super(sb, bdev_file, &sb_disk);
>  	if (err)
>  		goto out_blkdev_put;
>  
> -- 
> 2.39.2
>
Christoph Hellwig March 17, 2024, 9:34 p.m. UTC | #2
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 4153c9ddbe0b..ec9efa79d5a8 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -163,15 +163,16 @@  static const char *read_super_common(struct cache_sb *sb,  struct block_device *
 }
 
 
-static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
+static const char *read_super(struct cache_sb *sb, struct file *bdev_file,
 			      struct cache_sb_disk **res)
 {
 	const char *err;
+	struct block_device *bdev = file_bdev(bdev_file);
 	struct cache_sb_disk *s;
 	struct page *page;
 	unsigned int i;
 
-	page = read_cache_page_gfp(bdev->bd_inode->i_mapping,
+	page = read_cache_page_gfp(bdev_file->f_mapping,
 				   SB_OFFSET >> PAGE_SHIFT, GFP_KERNEL);
 	if (IS_ERR(page))
 		return "IO error";
@@ -2564,7 +2565,7 @@  static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 	if (set_blocksize(file_bdev(bdev_file), 4096))
 		goto out_blkdev_put;
 
-	err = read_super(sb, file_bdev(bdev_file), &sb_disk);
+	err = read_super(sb, bdev_file, &sb_disk);
 	if (err)
 		goto out_blkdev_put;