From: Jan Kara <jack@suse.cz>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: jack@suse.cz, hch@lst.de, brauner@kernel.org, axboe@kernel.dk,
linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org,
yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com
Subject: Re: [RFC v4 linux-next 11/19] btrfs: prevent direct access of bd_inode
Date: Fri, 15 Mar 2024 16:09:22 +0100 [thread overview]
Message-ID: <20240315150922.l7cnj7sclqsmg6xx@quack3> (raw)
In-Reply-To: <20240222124555.2049140-12-yukuai1@huaweicloud.com>
On Thu 22-02-24 20:45:47, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
>
> Now that all filesystems stash the bdev file, it's ok to get inode or
> 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
> ---
> fs/btrfs/disk-io.c | 17 +++++++++--------
> fs/btrfs/disk-io.h | 4 ++--
> fs/btrfs/super.c | 2 +-
> fs/btrfs/volumes.c | 15 +++++++--------
> fs/btrfs/zoned.c | 20 +++++++++++---------
> fs/btrfs/zoned.h | 4 ++--
> 6 files changed, 32 insertions(+), 30 deletions(-)
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index bececdd63b4d..344955765f3e 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -3235,7 +3235,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
> /*
> * Read super block and check the signature bytes only
> */
> - disk_super = btrfs_read_dev_super(fs_devices->latest_dev->bdev);
> + disk_super = btrfs_read_dev_super(fs_devices->latest_dev->bdev_file);
> if (IS_ERR(disk_super)) {
> ret = PTR_ERR(disk_super);
> goto fail_alloc;
> @@ -3656,17 +3656,18 @@ static void btrfs_end_super_write(struct bio *bio)
> bio_put(bio);
> }
>
> -struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev,
> +struct btrfs_super_block *btrfs_read_dev_one_super(struct file *bdev_file,
> int copy_num, bool drop_cache)
> {
> struct btrfs_super_block *super;
> struct page *page;
> u64 bytenr, bytenr_orig;
> - struct address_space *mapping = bdev->bd_inode->i_mapping;
> + struct block_device *bdev = file_bdev(bdev_file);
> + struct address_space *mapping = bdev_file->f_mapping;
> int ret;
>
> bytenr_orig = btrfs_sb_offset(copy_num);
> - ret = btrfs_sb_log_location_bdev(bdev, copy_num, READ, &bytenr);
> + ret = btrfs_sb_log_location_bdev(bdev_file, copy_num, READ, &bytenr);
> if (ret == -ENOENT)
> return ERR_PTR(-EINVAL);
> else if (ret)
> @@ -3707,7 +3708,7 @@ struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev,
> }
>
>
> -struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev)
> +struct btrfs_super_block *btrfs_read_dev_super(struct file *bdev_file)
> {
> struct btrfs_super_block *super, *latest = NULL;
> int i;
> @@ -3719,7 +3720,7 @@ struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev)
> * later supers, using BTRFS_SUPER_MIRROR_MAX instead
> */
> for (i = 0; i < 1; i++) {
> - super = btrfs_read_dev_one_super(bdev, i, false);
> + super = btrfs_read_dev_one_super(bdev_file, i, false);
> if (IS_ERR(super))
> continue;
>
> @@ -3749,7 +3750,7 @@ static int write_dev_supers(struct btrfs_device *device,
> struct btrfs_super_block *sb, int max_mirrors)
> {
> struct btrfs_fs_info *fs_info = device->fs_info;
> - struct address_space *mapping = device->bdev->bd_inode->i_mapping;
> + struct address_space *mapping = device->bdev_file->f_mapping;
> SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
> int i;
> int errors = 0;
> @@ -3866,7 +3867,7 @@ static int wait_dev_supers(struct btrfs_device *device, int max_mirrors)
> device->commit_total_bytes)
> break;
>
> - page = find_get_page(device->bdev->bd_inode->i_mapping,
> + page = find_get_page(device->bdev_file->f_mapping,
> bytenr >> PAGE_SHIFT);
> if (!page) {
> errors++;
> diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
> index 375f62ae3709..2c627885d8d1 100644
> --- a/fs/btrfs/disk-io.h
> +++ b/fs/btrfs/disk-io.h
> @@ -60,8 +60,8 @@ int btrfs_validate_super(struct btrfs_fs_info *fs_info,
> struct btrfs_super_block *sb, int mirror_num);
> int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount);
> int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors);
> -struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev);
> -struct btrfs_super_block *btrfs_read_dev_one_super(struct block_device *bdev,
> +struct btrfs_super_block *btrfs_read_dev_super(struct file *bdev_file);
> +struct btrfs_super_block *btrfs_read_dev_one_super(struct file *bdev_file,
> int copy_num, bool drop_cache);
> int btrfs_commit_super(struct btrfs_fs_info *fs_info);
> struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 40ae264fd3ed..9f50f20a1ba4 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -2286,7 +2286,7 @@ static int check_dev_super(struct btrfs_device *dev)
> return 0;
>
> /* Only need to check the primary super block. */
> - sb = btrfs_read_dev_one_super(dev->bdev, 0, true);
> + sb = btrfs_read_dev_one_super(dev->bdev_file, 0, true);
> if (IS_ERR(sb))
> return PTR_ERR(sb);
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index e12451ff911a..9fccfb156bd2 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -488,7 +488,7 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
> goto error;
> }
> invalidate_bdev(bdev);
> - *disk_super = btrfs_read_dev_super(bdev);
> + *disk_super = btrfs_read_dev_super(*bdev_file);
> if (IS_ERR(*disk_super)) {
> ret = PTR_ERR(*disk_super);
> fput(*bdev_file);
> @@ -1244,7 +1244,7 @@ void btrfs_release_disk_super(struct btrfs_super_block *super)
> put_page(page);
> }
>
> -static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev,
> +static struct btrfs_super_block *btrfs_read_disk_super(struct file *bdev_file,
> u64 bytenr, u64 bytenr_orig)
> {
> struct btrfs_super_block *disk_super;
> @@ -1253,7 +1253,7 @@ static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev
> pgoff_t index;
>
> /* make sure our super fits in the device */
> - if (bytenr + PAGE_SIZE >= bdev_nr_bytes(bdev))
> + if (bytenr + PAGE_SIZE >= bdev_nr_bytes(file_bdev(bdev_file)))
> return ERR_PTR(-EINVAL);
>
> /* make sure our super fits in the page */
> @@ -1266,7 +1266,7 @@ static struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev
> 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_file->f_mapping, index, GFP_KERNEL);
>
> if (IS_ERR(page))
> return ERR_CAST(page);
> @@ -1368,14 +1368,13 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags,
> return ERR_CAST(bdev_file);
>
> bytenr_orig = btrfs_sb_offset(0);
> - ret = btrfs_sb_log_location_bdev(file_bdev(bdev_file), 0, READ, &bytenr);
> + ret = btrfs_sb_log_location_bdev(bdev_file, 0, READ, &bytenr);
> if (ret) {
> device = ERR_PTR(ret);
> goto error_bdev_put;
> }
>
> - disk_super = btrfs_read_disk_super(file_bdev(bdev_file), bytenr,
> - bytenr_orig);
> + disk_super = btrfs_read_disk_super(bdev_file, bytenr, bytenr_orig);
> if (IS_ERR(disk_super)) {
> device = ERR_CAST(disk_super);
> goto error_bdev_put;
> @@ -2040,7 +2039,7 @@ static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info,
> const u64 bytenr = btrfs_sb_offset(copy_num);
> int ret;
>
> - disk_super = btrfs_read_disk_super(file_bdev(bdev_file), bytenr, bytenr);
> + disk_super = btrfs_read_disk_super(bdev_file, bytenr, bytenr);
> if (IS_ERR(disk_super))
> return;
>
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index 12d77aba0148..9e4e2951cdf5 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -81,7 +81,7 @@ static int copy_zone_info_cb(struct blk_zone *zone, unsigned int idx, void *data
> return 0;
> }
>
> -static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
> +static int sb_write_pointer(struct file *bdev_file, struct blk_zone *zones,
> u64 *wp_ret)
> {
> bool empty[BTRFS_NR_SB_LOG_ZONES];
> @@ -118,7 +118,7 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
> return -ENOENT;
> } else if (full[0] && full[1]) {
> /* Compare two super blocks */
> - struct address_space *mapping = bdev->bd_inode->i_mapping;
> + struct address_space *mapping = bdev_file->f_mapping;
> struct page *page[BTRFS_NR_SB_LOG_ZONES];
> struct btrfs_super_block *super[BTRFS_NR_SB_LOG_ZONES];
> int i;
> @@ -562,7 +562,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
> BLK_ZONE_TYPE_CONVENTIONAL)
> continue;
>
> - ret = sb_write_pointer(device->bdev,
> + ret = sb_write_pointer(device->bdev_file,
> &zone_info->sb_zones[sb_pos], &sb_wp);
> if (ret != -ENOENT && ret) {
> btrfs_err_in_rcu(device->fs_info,
> @@ -798,7 +798,7 @@ int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info, unsigned long *mount
> return 0;
> }
>
> -static int sb_log_location(struct block_device *bdev, struct blk_zone *zones,
> +static int sb_log_location(struct file *bdev_file, struct blk_zone *zones,
> int rw, u64 *bytenr_ret)
> {
> u64 wp;
> @@ -809,7 +809,7 @@ static int sb_log_location(struct block_device *bdev, struct blk_zone *zones,
> return 0;
> }
>
> - ret = sb_write_pointer(bdev, zones, &wp);
> + ret = sb_write_pointer(bdev_file, zones, &wp);
> if (ret != -ENOENT && ret < 0)
> return ret;
>
> @@ -827,7 +827,8 @@ static int sb_log_location(struct block_device *bdev, struct blk_zone *zones,
> ASSERT(sb_zone_is_full(reset));
>
> nofs_flags = memalloc_nofs_save();
> - ret = blkdev_zone_mgmt(bdev, REQ_OP_ZONE_RESET,
> + ret = blkdev_zone_mgmt(file_bdev(bdev_file),
> + REQ_OP_ZONE_RESET,
> reset->start, reset->len);
> memalloc_nofs_restore(nofs_flags);
> if (ret)
> @@ -859,10 +860,11 @@ static int sb_log_location(struct block_device *bdev, struct blk_zone *zones,
>
> }
>
> -int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw,
> +int btrfs_sb_log_location_bdev(struct file *bdev_file, int mirror, int rw,
> u64 *bytenr_ret)
> {
> struct blk_zone zones[BTRFS_NR_SB_LOG_ZONES];
> + struct block_device *bdev = file_bdev(bdev_file);
> sector_t zone_sectors;
> u32 sb_zone;
> int ret;
> @@ -896,7 +898,7 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw,
> if (ret != BTRFS_NR_SB_LOG_ZONES)
> return -EIO;
>
> - return sb_log_location(bdev, zones, rw, bytenr_ret);
> + return sb_log_location(bdev_file, zones, rw, bytenr_ret);
> }
>
> int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw,
> @@ -920,7 +922,7 @@ int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw,
> if (zone_num + 1 >= zinfo->nr_zones)
> return -ENOENT;
>
> - return sb_log_location(device->bdev,
> + return sb_log_location(device->bdev_file,
> &zinfo->sb_zones[BTRFS_NR_SB_LOG_ZONES * mirror],
> rw, bytenr_ret);
> }
> diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
> index 77c4321e331f..32680a04aa1f 100644
> --- a/fs/btrfs/zoned.h
> +++ b/fs/btrfs/zoned.h
> @@ -61,7 +61,7 @@ void btrfs_destroy_dev_zone_info(struct btrfs_device *device);
> struct btrfs_zoned_device_info *btrfs_clone_dev_zone_info(struct btrfs_device *orig_dev);
> int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info);
> int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info, unsigned long *mount_opt);
> -int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw,
> +int btrfs_sb_log_location_bdev(struct file *bdev_file, int mirror, int rw,
> u64 *bytenr_ret);
> int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw,
> u64 *bytenr_ret);
> @@ -142,7 +142,7 @@ static inline int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info,
> return 0;
> }
>
> -static inline int btrfs_sb_log_location_bdev(struct block_device *bdev,
> +static inline int btrfs_sb_log_location_bdev(struct file *bdev_file,
> int mirror, int rw, u64 *bytenr_ret)
> {
> *bytenr_ret = btrfs_sb_offset(mirror);
> --
> 2.39.2
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-03-15 15:09 UTC|newest]
Thread overview: 97+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-22 12:45 [RFC v4 linux-next 00/19] fs & block: remove bdev->bd_inode Yu Kuai
2024-02-22 12:45 ` [RFC v4 linux-next 01/19] block: move two helpers into bdev.c Yu Kuai
2024-03-15 14:31 ` Jan Kara
2024-03-17 21:19 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 02/19] block: remove sync_blockdev_nowait() Yu Kuai
2024-03-15 14:34 ` Jan Kara
2024-03-17 21:19 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 03/19] block: remove sync_blockdev_range() Yu Kuai
2024-03-15 14:37 ` Jan Kara
2024-03-17 21:21 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 04/19] block: prevent direct access of bd_inode Yu Kuai
2024-03-15 14:44 ` Jan Kara
2024-03-17 21:23 ` Christoph Hellwig
2024-03-22 5:44 ` Al Viro
2024-02-22 12:45 ` [RFC v4 linux-next 05/19] bcachefs: remove dead function bdev_sectors() Yu Kuai
2024-03-15 14:42 ` Jan Kara
2024-03-17 21:23 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 06/19] cramfs: prevent direct access of bd_inode Yu Kuai
2024-03-15 14:44 ` Jan Kara
2024-03-17 21:23 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 07/19] erofs: " Yu Kuai
2024-03-15 14:45 ` Jan Kara
2024-03-17 21:24 ` Christoph Hellwig
2024-03-18 2:39 ` Gao Xiang
2024-02-22 12:45 ` [RFC v4 linux-next 08/19] nilfs2: " Yu Kuai
2024-03-15 14:49 ` Jan Kara
2024-03-17 21:24 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 09/19] gfs2: " Yu Kuai
2024-03-15 14:54 ` Jan Kara
2024-03-17 21:24 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 10/19] s390/dasd: use bdev api in dasd_format() Yu Kuai
2024-03-15 14:55 ` Jan Kara
2024-03-17 21:25 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 11/19] btrfs: prevent direct access of bd_inode Yu Kuai
2024-03-15 15:09 ` Jan Kara [this message]
2024-03-17 21:25 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 12/19] ext4: remove block_device_ejected() Yu Kuai
2024-02-22 12:45 ` [RFC v4 linux-next 13/19] ext4: prevent direct access of bd_inode Yu Kuai
2024-03-15 14:58 ` Jan Kara
2024-03-17 21:25 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 14/19] jbd2: " Yu Kuai
2024-03-15 15:06 ` Jan Kara
2024-03-17 21:26 ` Christoph Hellwig
2024-03-18 1:10 ` Yu Kuai
2024-02-22 12:45 ` [RFC v4 linux-next 15/19] bcache: " Yu Kuai
2024-03-15 15:11 ` Jan Kara
2024-03-17 21:34 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 16/19] block2mtd: " Yu Kuai
2024-03-15 15:12 ` Jan Kara
2024-03-17 21:36 ` Christoph Hellwig
2024-02-22 12:45 ` [RFC v4 linux-next 17/19] dm-vdo: " Yu Kuai
2024-02-28 13:41 ` Christoph Hellwig
2024-03-18 9:11 ` Jan Kara
2024-03-18 9:19 ` Jan Kara
2024-03-18 13:38 ` Yu Kuai
2024-03-19 2:00 ` Matthew Sakai
2024-02-22 12:45 ` [RFC v4 linux-next 18/19] scsi: factor out a helper bdev_read_folio() from scsi_bios_ptable() Yu Kuai
2024-03-17 21:36 ` Christoph Hellwig
2024-03-18 1:12 ` Yu Kuai
2024-03-18 9:22 ` Jan Kara
2024-02-22 12:45 ` [RFC v4 linux-next 19/19] fs & block: remove bdev->bd_inode Yu Kuai
2024-03-17 21:38 ` Christoph Hellwig
2024-03-18 1:26 ` Yu Kuai
2024-03-18 1:32 ` Christoph Hellwig
2024-03-18 1:51 ` Yu Kuai
2024-03-18 7:19 ` Yu Kuai
2024-03-18 10:07 ` Christian Brauner
2024-03-18 10:29 ` Christian Brauner
2024-03-18 10:46 ` Christian Brauner
2024-03-18 11:57 ` Yu Kuai
2024-03-18 23:35 ` Christoph Hellwig
2024-03-18 23:22 ` Christoph Hellwig
2024-03-19 8:26 ` Yu Kuai
2024-03-21 11:27 ` Jan Kara
2024-03-21 12:15 ` Yu Kuai
2024-03-22 6:37 ` Al Viro
2024-03-22 6:39 ` Al Viro
2024-03-22 6:52 ` Yu Kuai
2024-03-22 12:57 ` Jan Kara
2024-03-22 13:57 ` Christian Brauner
2024-03-22 15:43 ` Al Viro
2024-03-22 16:16 ` Al Viro
2024-03-22 6:33 ` Al Viro
2024-03-22 7:09 ` Yu Kuai
2024-03-22 16:01 ` Al Viro
2024-03-22 13:10 ` Jan Kara
2024-03-22 14:57 ` Al Viro
2024-03-25 1:06 ` Christoph Hellwig
2024-02-28 13:42 ` [RFC v4 linux-next 00/19] " Christoph Hellwig
2024-03-15 12:08 ` Yu Kuai
2024-03-15 13:54 ` Christian Brauner
2024-03-16 2:49 ` Yu Kuai
2024-03-18 9:39 ` Christian Brauner
2024-03-19 1:18 ` Yu Kuai
2024-03-19 1:43 ` Yu Kuai
2024-03-19 2:13 ` Matthew Sakai
2024-03-19 2:27 ` Yu Kuai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240315150922.l7cnj7sclqsmg6xx@quack3 \
--to=jack@suse.cz \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai1@huaweicloud.com \
--cc=yukuai3@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox