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 14/19] jbd2: prevent direct access of bd_inode
Date: Fri, 15 Mar 2024 16:06:45 +0100 [thread overview]
Message-ID: <20240315150645.jdegmdoahjdz7uo7@quack3> (raw)
In-Reply-To: <20240222124555.2049140-15-yukuai1@huaweicloud.com>
On Thu 22-02-24 20:45:50, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
>
> Now that all filesystems stash the bdev file, 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
> ---
> fs/ext4/super.c | 2 +-
> fs/jbd2/journal.c | 26 +++++++++++++++-----------
> include/linux/jbd2.h | 18 ++++++++++++++----
> 3 files changed, 30 insertions(+), 16 deletions(-)
>
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 55b3df71bf5e..4df1a5cfe0a5 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -5918,7 +5918,7 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb,
> if (IS_ERR(bdev_file))
> return ERR_CAST(bdev_file);
>
> - journal = jbd2_journal_init_dev(file_bdev(bdev_file), sb->s_bdev, j_start,
> + journal = jbd2_journal_init_dev(bdev_file, sb->s_bdev_file, j_start,
> j_len, sb->s_blocksize);
> if (IS_ERR(journal)) {
> ext4_msg(sb, KERN_ERR, "failed to create device journal");
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index b6c114c11b97..abd42a6ccd0e 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -1516,11 +1516,12 @@ static int journal_load_superblock(journal_t *journal)
> * very few fields yet: that has to wait until we have created the
> * journal structures from from scratch, or loaded them from disk. */
>
> -static journal_t *journal_init_common(struct block_device *bdev,
> - struct block_device *fs_dev,
> +static journal_t *journal_init_common(struct file *bdev_file,
> + struct file *fs_dev_file,
> unsigned long long start, int len, int blocksize)
> {
> static struct lock_class_key jbd2_trans_commit_key;
> + struct block_device *bdev = file_bdev(bdev_file);
> journal_t *journal;
> int err;
> int n;
> @@ -1531,7 +1532,9 @@ static journal_t *journal_init_common(struct block_device *bdev,
>
> journal->j_blocksize = blocksize;
> journal->j_dev = bdev;
> - journal->j_fs_dev = fs_dev;
> + journal->j_dev_file = bdev_file;
> + journal->j_fs_dev = file_bdev(fs_dev_file);
> + journal->j_fs_dev_file = fs_dev_file;
> journal->j_blk_offset = start;
> journal->j_total_len = len;
> jbd2_init_fs_dev_write_error(journal);
> @@ -1628,8 +1631,8 @@ static journal_t *journal_init_common(struct block_device *bdev,
>
> /**
> * journal_t * jbd2_journal_init_dev() - creates and initialises a journal structure
> - * @bdev: Block device on which to create the journal
> - * @fs_dev: Device which hold journalled filesystem for this journal.
> + * @bdev_file: Opened block device on which to create the journal
> + * @fs_dev_file: Opened device which hold journalled filesystem for this journal.
> * @start: Block nr Start of journal.
> * @len: Length of the journal in blocks.
> * @blocksize: blocksize of journalling device
> @@ -1640,13 +1643,13 @@ static journal_t *journal_init_common(struct block_device *bdev,
> * range of blocks on an arbitrary block device.
> *
> */
> -journal_t *jbd2_journal_init_dev(struct block_device *bdev,
> - struct block_device *fs_dev,
> +journal_t *jbd2_journal_init_dev(struct file *bdev_file,
> + struct file *fs_dev_file,
> unsigned long long start, int len, int blocksize)
> {
> journal_t *journal;
>
> - journal = journal_init_common(bdev, fs_dev, start, len, blocksize);
> + journal = journal_init_common(bdev_file, fs_dev_file, start, len, blocksize);
> if (IS_ERR(journal))
> return ERR_CAST(journal);
>
> @@ -1683,8 +1686,9 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
> inode->i_sb->s_id, inode->i_ino, (long long) inode->i_size,
> inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize);
>
> - journal = journal_init_common(inode->i_sb->s_bdev, inode->i_sb->s_bdev,
> - blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits,
> + journal = journal_init_common(inode->i_sb->s_bdev_file,
> + inode->i_sb->s_bdev_file, blocknr,
> + inode->i_size >> inode->i_sb->s_blocksize_bits,
> inode->i_sb->s_blocksize);
> if (IS_ERR(journal))
> return ERR_CAST(journal);
> @@ -2009,7 +2013,7 @@ static int __jbd2_journal_erase(journal_t *journal, unsigned int flags)
> byte_count = (block_stop - block_start + 1) *
> journal->j_blocksize;
>
> - truncate_inode_pages_range(journal->j_dev->bd_inode->i_mapping,
> + truncate_inode_pages_range(journal->j_dev_file->f_mapping,
> byte_start, byte_stop);
>
> if (flags & JBD2_JOURNAL_FLUSH_DISCARD) {
> diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
> index 971f3e826e15..fc26730ae8ef 100644
> --- a/include/linux/jbd2.h
> +++ b/include/linux/jbd2.h
> @@ -968,6 +968,11 @@ struct journal_s
> */
> struct block_device *j_dev;
>
> + /**
> + * @j_dev_file: Opended device @j_dev.
> + */
> + struct file *j_dev_file;
> +
> /**
> * @j_blocksize: Block size for the location where we store the journal.
> */
> @@ -993,6 +998,11 @@ struct journal_s
> */
> struct block_device *j_fs_dev;
>
> + /**
> + * @j_fs_dev_file: Opened device @j_fs_dev.
> + */
> + struct file *j_fs_dev_file;
> +
> /**
> * @j_fs_dev_wb_err:
> *
> @@ -1533,8 +1543,8 @@ extern void jbd2_journal_unlock_updates (journal_t *);
>
> void jbd2_journal_wait_updates(journal_t *);
>
> -extern journal_t * jbd2_journal_init_dev(struct block_device *bdev,
> - struct block_device *fs_dev,
> +extern journal_t *jbd2_journal_init_dev(struct file *bdev_file,
> + struct file *fs_dev_file,
> unsigned long long start, int len, int bsize);
> extern journal_t * jbd2_journal_init_inode (struct inode *);
> extern int jbd2_journal_update_format (journal_t *);
> @@ -1696,7 +1706,7 @@ static inline void jbd2_journal_abort_handle(handle_t *handle)
>
> static inline void jbd2_init_fs_dev_write_error(journal_t *journal)
> {
> - struct address_space *mapping = journal->j_fs_dev->bd_inode->i_mapping;
> + struct address_space *mapping = journal->j_fs_dev_file->f_mapping;
>
> /*
> * Save the original wb_err value of client fs's bdev mapping which
> @@ -1707,7 +1717,7 @@ static inline void jbd2_init_fs_dev_write_error(journal_t *journal)
>
> static inline int jbd2_check_fs_dev_write_error(journal_t *journal)
> {
> - struct address_space *mapping = journal->j_fs_dev->bd_inode->i_mapping;
> + struct address_space *mapping = journal->j_fs_dev_file->f_mapping;
>
> return errseq_check(&mapping->wb_err,
> READ_ONCE(journal->j_fs_dev_wb_err));
> --
> 2.39.2
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-03-15 15:06 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
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 [this message]
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=20240315150645.jdegmdoahjdz7uo7@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