mirror of
https://github.com/torvalds/linux
synced 2024-10-14 15:29:13 +00:00
ext4: port block device access to file
Link: https://lore.kernel.org/r/20240123-vfs-bdev-file-v2-21-adbd023e19cc@kernel.org Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
87b355f448
commit
61ead71476
|
@ -1548,7 +1548,7 @@ struct ext4_sb_info {
|
||||||
unsigned long s_commit_interval;
|
unsigned long s_commit_interval;
|
||||||
u32 s_max_batch_time;
|
u32 s_max_batch_time;
|
||||||
u32 s_min_batch_time;
|
u32 s_min_batch_time;
|
||||||
struct bdev_handle *s_journal_bdev_handle;
|
struct file *s_journal_bdev_file;
|
||||||
#ifdef CONFIG_QUOTA
|
#ifdef CONFIG_QUOTA
|
||||||
/* Names of quota files with journalled quota */
|
/* Names of quota files with journalled quota */
|
||||||
char __rcu *s_qf_names[EXT4_MAXQUOTAS];
|
char __rcu *s_qf_names[EXT4_MAXQUOTAS];
|
||||||
|
|
|
@ -576,9 +576,9 @@ static bool ext4_getfsmap_is_valid_device(struct super_block *sb,
|
||||||
if (fm->fmr_device == 0 || fm->fmr_device == UINT_MAX ||
|
if (fm->fmr_device == 0 || fm->fmr_device == UINT_MAX ||
|
||||||
fm->fmr_device == new_encode_dev(sb->s_bdev->bd_dev))
|
fm->fmr_device == new_encode_dev(sb->s_bdev->bd_dev))
|
||||||
return true;
|
return true;
|
||||||
if (EXT4_SB(sb)->s_journal_bdev_handle &&
|
if (EXT4_SB(sb)->s_journal_bdev_file &&
|
||||||
fm->fmr_device ==
|
fm->fmr_device ==
|
||||||
new_encode_dev(EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev))
|
new_encode_dev(file_bdev(EXT4_SB(sb)->s_journal_bdev_file)->bd_dev))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -648,9 +648,9 @@ int ext4_getfsmap(struct super_block *sb, struct ext4_fsmap_head *head,
|
||||||
memset(handlers, 0, sizeof(handlers));
|
memset(handlers, 0, sizeof(handlers));
|
||||||
handlers[0].gfd_dev = new_encode_dev(sb->s_bdev->bd_dev);
|
handlers[0].gfd_dev = new_encode_dev(sb->s_bdev->bd_dev);
|
||||||
handlers[0].gfd_fn = ext4_getfsmap_datadev;
|
handlers[0].gfd_fn = ext4_getfsmap_datadev;
|
||||||
if (EXT4_SB(sb)->s_journal_bdev_handle) {
|
if (EXT4_SB(sb)->s_journal_bdev_file) {
|
||||||
handlers[1].gfd_dev = new_encode_dev(
|
handlers[1].gfd_dev = new_encode_dev(
|
||||||
EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev);
|
file_bdev(EXT4_SB(sb)->s_journal_bdev_file)->bd_dev);
|
||||||
handlers[1].gfd_fn = ext4_getfsmap_logdev;
|
handlers[1].gfd_fn = ext4_getfsmap_logdev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1359,14 +1359,14 @@ static void ext4_put_super(struct super_block *sb)
|
||||||
|
|
||||||
sync_blockdev(sb->s_bdev);
|
sync_blockdev(sb->s_bdev);
|
||||||
invalidate_bdev(sb->s_bdev);
|
invalidate_bdev(sb->s_bdev);
|
||||||
if (sbi->s_journal_bdev_handle) {
|
if (sbi->s_journal_bdev_file) {
|
||||||
/*
|
/*
|
||||||
* Invalidate the journal device's buffers. We don't want them
|
* Invalidate the journal device's buffers. We don't want them
|
||||||
* floating about in memory - the physical journal device may
|
* floating about in memory - the physical journal device may
|
||||||
* hotswapped, and it breaks the `ro-after' testing code.
|
* hotswapped, and it breaks the `ro-after' testing code.
|
||||||
*/
|
*/
|
||||||
sync_blockdev(sbi->s_journal_bdev_handle->bdev);
|
sync_blockdev(file_bdev(sbi->s_journal_bdev_file));
|
||||||
invalidate_bdev(sbi->s_journal_bdev_handle->bdev);
|
invalidate_bdev(file_bdev(sbi->s_journal_bdev_file));
|
||||||
}
|
}
|
||||||
|
|
||||||
ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
|
ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
|
||||||
|
@ -4233,7 +4233,7 @@ int ext4_calculate_overhead(struct super_block *sb)
|
||||||
* Add the internal journal blocks whether the journal has been
|
* Add the internal journal blocks whether the journal has been
|
||||||
* loaded or not
|
* loaded or not
|
||||||
*/
|
*/
|
||||||
if (sbi->s_journal && !sbi->s_journal_bdev_handle)
|
if (sbi->s_journal && !sbi->s_journal_bdev_file)
|
||||||
overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len);
|
overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len);
|
||||||
else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) {
|
else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) {
|
||||||
/* j_inum for internal journal is non-zero */
|
/* j_inum for internal journal is non-zero */
|
||||||
|
@ -5670,9 +5670,9 @@ failed_mount9: __maybe_unused
|
||||||
#endif
|
#endif
|
||||||
fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
|
fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
|
||||||
brelse(sbi->s_sbh);
|
brelse(sbi->s_sbh);
|
||||||
if (sbi->s_journal_bdev_handle) {
|
if (sbi->s_journal_bdev_file) {
|
||||||
invalidate_bdev(sbi->s_journal_bdev_handle->bdev);
|
invalidate_bdev(file_bdev(sbi->s_journal_bdev_file));
|
||||||
bdev_release(sbi->s_journal_bdev_handle);
|
fput(sbi->s_journal_bdev_file);
|
||||||
}
|
}
|
||||||
out_fail:
|
out_fail:
|
||||||
invalidate_bdev(sb->s_bdev);
|
invalidate_bdev(sb->s_bdev);
|
||||||
|
@ -5842,30 +5842,30 @@ static journal_t *ext4_open_inode_journal(struct super_block *sb,
|
||||||
return journal;
|
return journal;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bdev_handle *ext4_get_journal_blkdev(struct super_block *sb,
|
static struct file *ext4_get_journal_blkdev(struct super_block *sb,
|
||||||
dev_t j_dev, ext4_fsblk_t *j_start,
|
dev_t j_dev, ext4_fsblk_t *j_start,
|
||||||
ext4_fsblk_t *j_len)
|
ext4_fsblk_t *j_len)
|
||||||
{
|
{
|
||||||
struct buffer_head *bh;
|
struct buffer_head *bh;
|
||||||
struct block_device *bdev;
|
struct block_device *bdev;
|
||||||
struct bdev_handle *bdev_handle;
|
struct file *bdev_file;
|
||||||
int hblock, blocksize;
|
int hblock, blocksize;
|
||||||
ext4_fsblk_t sb_block;
|
ext4_fsblk_t sb_block;
|
||||||
unsigned long offset;
|
unsigned long offset;
|
||||||
struct ext4_super_block *es;
|
struct ext4_super_block *es;
|
||||||
int errno;
|
int errno;
|
||||||
|
|
||||||
bdev_handle = bdev_open_by_dev(j_dev,
|
bdev_file = bdev_file_open_by_dev(j_dev,
|
||||||
BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
|
BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
|
||||||
sb, &fs_holder_ops);
|
sb, &fs_holder_ops);
|
||||||
if (IS_ERR(bdev_handle)) {
|
if (IS_ERR(bdev_file)) {
|
||||||
ext4_msg(sb, KERN_ERR,
|
ext4_msg(sb, KERN_ERR,
|
||||||
"failed to open journal device unknown-block(%u,%u) %ld",
|
"failed to open journal device unknown-block(%u,%u) %ld",
|
||||||
MAJOR(j_dev), MINOR(j_dev), PTR_ERR(bdev_handle));
|
MAJOR(j_dev), MINOR(j_dev), PTR_ERR(bdev_file));
|
||||||
return bdev_handle;
|
return bdev_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
bdev = bdev_handle->bdev;
|
bdev = file_bdev(bdev_file);
|
||||||
blocksize = sb->s_blocksize;
|
blocksize = sb->s_blocksize;
|
||||||
hblock = bdev_logical_block_size(bdev);
|
hblock = bdev_logical_block_size(bdev);
|
||||||
if (blocksize < hblock) {
|
if (blocksize < hblock) {
|
||||||
|
@ -5912,12 +5912,12 @@ static struct bdev_handle *ext4_get_journal_blkdev(struct super_block *sb,
|
||||||
*j_start = sb_block + 1;
|
*j_start = sb_block + 1;
|
||||||
*j_len = ext4_blocks_count(es);
|
*j_len = ext4_blocks_count(es);
|
||||||
brelse(bh);
|
brelse(bh);
|
||||||
return bdev_handle;
|
return bdev_file;
|
||||||
|
|
||||||
out_bh:
|
out_bh:
|
||||||
brelse(bh);
|
brelse(bh);
|
||||||
out_bdev:
|
out_bdev:
|
||||||
bdev_release(bdev_handle);
|
fput(bdev_file);
|
||||||
return ERR_PTR(errno);
|
return ERR_PTR(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5927,14 +5927,14 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb,
|
||||||
journal_t *journal;
|
journal_t *journal;
|
||||||
ext4_fsblk_t j_start;
|
ext4_fsblk_t j_start;
|
||||||
ext4_fsblk_t j_len;
|
ext4_fsblk_t j_len;
|
||||||
struct bdev_handle *bdev_handle;
|
struct file *bdev_file;
|
||||||
int errno = 0;
|
int errno = 0;
|
||||||
|
|
||||||
bdev_handle = ext4_get_journal_blkdev(sb, j_dev, &j_start, &j_len);
|
bdev_file = ext4_get_journal_blkdev(sb, j_dev, &j_start, &j_len);
|
||||||
if (IS_ERR(bdev_handle))
|
if (IS_ERR(bdev_file))
|
||||||
return ERR_CAST(bdev_handle);
|
return ERR_CAST(bdev_file);
|
||||||
|
|
||||||
journal = jbd2_journal_init_dev(bdev_handle->bdev, sb->s_bdev, j_start,
|
journal = jbd2_journal_init_dev(file_bdev(bdev_file), sb->s_bdev, j_start,
|
||||||
j_len, sb->s_blocksize);
|
j_len, sb->s_blocksize);
|
||||||
if (IS_ERR(journal)) {
|
if (IS_ERR(journal)) {
|
||||||
ext4_msg(sb, KERN_ERR, "failed to create device journal");
|
ext4_msg(sb, KERN_ERR, "failed to create device journal");
|
||||||
|
@ -5949,14 +5949,14 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb,
|
||||||
goto out_journal;
|
goto out_journal;
|
||||||
}
|
}
|
||||||
journal->j_private = sb;
|
journal->j_private = sb;
|
||||||
EXT4_SB(sb)->s_journal_bdev_handle = bdev_handle;
|
EXT4_SB(sb)->s_journal_bdev_file = bdev_file;
|
||||||
ext4_init_journal_params(sb, journal);
|
ext4_init_journal_params(sb, journal);
|
||||||
return journal;
|
return journal;
|
||||||
|
|
||||||
out_journal:
|
out_journal:
|
||||||
jbd2_journal_destroy(journal);
|
jbd2_journal_destroy(journal);
|
||||||
out_bdev:
|
out_bdev:
|
||||||
bdev_release(bdev_handle);
|
fput(bdev_file);
|
||||||
return ERR_PTR(errno);
|
return ERR_PTR(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7314,12 +7314,12 @@ static inline int ext3_feature_set_ok(struct super_block *sb)
|
||||||
static void ext4_kill_sb(struct super_block *sb)
|
static void ext4_kill_sb(struct super_block *sb)
|
||||||
{
|
{
|
||||||
struct ext4_sb_info *sbi = EXT4_SB(sb);
|
struct ext4_sb_info *sbi = EXT4_SB(sb);
|
||||||
struct bdev_handle *handle = sbi ? sbi->s_journal_bdev_handle : NULL;
|
struct file *bdev_file = sbi ? sbi->s_journal_bdev_file : NULL;
|
||||||
|
|
||||||
kill_block_super(sb);
|
kill_block_super(sb);
|
||||||
|
|
||||||
if (handle)
|
if (bdev_file)
|
||||||
bdev_release(handle);
|
fput(bdev_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct file_system_type ext4_fs_type = {
|
static struct file_system_type ext4_fs_type = {
|
||||||
|
|
Loading…
Reference in a new issue