Re: [PATCH v2 33/34] block: expose bdev_file_inode()

Jan Kara
2024-02-01T10:10:00Z

On Tue 23-01-24 14:26:50, Christian Brauner wrote:
> Now that we open block devices as files we don't need to rely on
> bd_inode to get to the correct inode. Use the helper.
>
> We could use bdev_file->f_inode directly here since we know that
> @f_inode refers to a bdev fs inode but it is generically correct to use
> bdev_file->f_mapping->host since that will also work for bdev_files
> opened from userspace.
>
> Signed-off-by: Christian Brauner <brauner@kernel.org>

I think you wouldn't need this patch, if you picked up patch:
https://lore.kernel.org/all/20231211140833.975935-1-yukuai1@huaweicloud.com

from previous Yu Kuai's series. Because the only user of bdev_file_inode()
in ext4 is actually dead code...

Honza

> ---
> block/bdev.c | 2 +-
> block/fops.c | 5 -----
> include/linux/blkdev.h | 5 +++++
> 3 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/block/bdev.c b/block/bdev.c
> index 4b47003d8082..185c43ebeea5 100644
> --- a/block/bdev.c
> +++ b/block/bdev.c
> @@ -51,7 +51,7 @@ EXPORT_SYMBOL(I_BDEV);
>
> struct block_device *file_bdev(struct file *bdev_file)
> {
> - return I_BDEV(bdev_file->f_mapping->host);
> + return I_BDEV(bdev_file_inode(bdev_file));
> }
> EXPORT_SYMBOL(file_bdev);
>
> diff --git a/block/fops.c b/block/fops.c
> index a0bff2c0d88d..240d968c281c 100644
> --- a/block/fops.c
> +++ b/block/fops.c
> @@ -19,11 +19,6 @@
> #include <linux/module.h>
> #include "blk.h"
>
> -static inline struct inode *bdev_file_inode(struct file *file)
> -{
> - return file->f_mapping->host;
> -}
> -
> static blk_opf_t dio_bio_write_op(struct kiocb *iocb)
> {
> blk_opf_t opf = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE;
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 2f5dbde23094..4b7080e56e44 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -1490,6 +1490,11 @@ void blkdev_put_no_open(struct block_device *bdev);
> struct block_device *I_BDEV(struct inode *inode);
> struct block_device *file_bdev(struct file *bdev_file);
>
> +static inline struct inode *bdev_file_inode(struct file *file)
> +{
> + return file->f_mapping->host;
> +}
> +
> #ifdef CONFIG_BLOCK
> void invalidate_bdev(struct block_device *bdev);
> int sync_blockdev(struct block_device *bdev);
>
> --
> 2.43.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR