Skip to content

Commit d577c8a

Browse files
jankarabrauner
authored andcommitted
ext4: Convert to bdev_open_by_dev()
Convert ext4 to use bdev_open_by_dev() and pass the handle around. CC: linux-ext4@vger.kernel.org CC: Ted Tso <tytso@mit.edu> Acked-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20230927093442.25915-22-jack@suse.cz Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 4984572 commit d577c8a

3 files changed

Lines changed: 33 additions & 30 deletions

File tree

fs/ext4/ext4.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ struct ext4_sb_info {
15371537
unsigned long s_commit_interval;
15381538
u32 s_max_batch_time;
15391539
u32 s_min_batch_time;
1540-
struct block_device *s_journal_bdev;
1540+
struct bdev_handle *s_journal_bdev_handle;
15411541
#ifdef CONFIG_QUOTA
15421542
/* Names of quota files with journalled quota */
15431543
char __rcu *s_qf_names[EXT4_MAXQUOTAS];

fs/ext4/fsmap.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,9 @@ static bool ext4_getfsmap_is_valid_device(struct super_block *sb,
576576
if (fm->fmr_device == 0 || fm->fmr_device == UINT_MAX ||
577577
fm->fmr_device == new_encode_dev(sb->s_bdev->bd_dev))
578578
return true;
579-
if (EXT4_SB(sb)->s_journal_bdev &&
580-
fm->fmr_device == new_encode_dev(EXT4_SB(sb)->s_journal_bdev->bd_dev))
579+
if (EXT4_SB(sb)->s_journal_bdev_handle &&
580+
fm->fmr_device ==
581+
new_encode_dev(EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev))
581582
return true;
582583
return false;
583584
}
@@ -647,9 +648,9 @@ int ext4_getfsmap(struct super_block *sb, struct ext4_fsmap_head *head,
647648
memset(handlers, 0, sizeof(handlers));
648649
handlers[0].gfd_dev = new_encode_dev(sb->s_bdev->bd_dev);
649650
handlers[0].gfd_fn = ext4_getfsmap_datadev;
650-
if (EXT4_SB(sb)->s_journal_bdev) {
651+
if (EXT4_SB(sb)->s_journal_bdev_handle) {
651652
handlers[1].gfd_dev = new_encode_dev(
652-
EXT4_SB(sb)->s_journal_bdev->bd_dev);
653+
EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev);
653654
handlers[1].gfd_fn = ext4_getfsmap_logdev;
654655
}
655656

fs/ext4/super.c

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,14 +1351,14 @@ static void ext4_put_super(struct super_block *sb)
13511351

13521352
sync_blockdev(sb->s_bdev);
13531353
invalidate_bdev(sb->s_bdev);
1354-
if (sbi->s_journal_bdev) {
1354+
if (sbi->s_journal_bdev_handle) {
13551355
/*
13561356
* Invalidate the journal device's buffers. We don't want them
13571357
* floating about in memory - the physical journal device may
13581358
* hotswapped, and it breaks the `ro-after' testing code.
13591359
*/
1360-
sync_blockdev(sbi->s_journal_bdev);
1361-
invalidate_bdev(sbi->s_journal_bdev);
1360+
sync_blockdev(sbi->s_journal_bdev_handle->bdev);
1361+
invalidate_bdev(sbi->s_journal_bdev_handle->bdev);
13621362
}
13631363

13641364
ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
@@ -4233,7 +4233,7 @@ int ext4_calculate_overhead(struct super_block *sb)
42334233
* Add the internal journal blocks whether the journal has been
42344234
* loaded or not
42354235
*/
4236-
if (sbi->s_journal && !sbi->s_journal_bdev)
4236+
if (sbi->s_journal && !sbi->s_journal_bdev_handle)
42374237
overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len);
42384238
else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) {
42394239
/* j_inum for internal journal is non-zero */
@@ -5670,9 +5670,9 @@ failed_mount9: __maybe_unused
56705670
#endif
56715671
fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
56725672
brelse(sbi->s_sbh);
5673-
if (sbi->s_journal_bdev) {
5674-
invalidate_bdev(sbi->s_journal_bdev);
5675-
blkdev_put(sbi->s_journal_bdev, sb);
5673+
if (sbi->s_journal_bdev_handle) {
5674+
invalidate_bdev(sbi->s_journal_bdev_handle->bdev);
5675+
bdev_release(sbi->s_journal_bdev_handle);
56765676
}
56775677
out_fail:
56785678
invalidate_bdev(sb->s_bdev);
@@ -5842,12 +5842,13 @@ static journal_t *ext4_open_inode_journal(struct super_block *sb,
58425842
return journal;
58435843
}
58445844

5845-
static struct block_device *ext4_get_journal_blkdev(struct super_block *sb,
5845+
static struct bdev_handle *ext4_get_journal_blkdev(struct super_block *sb,
58465846
dev_t j_dev, ext4_fsblk_t *j_start,
58475847
ext4_fsblk_t *j_len)
58485848
{
58495849
struct buffer_head *bh;
58505850
struct block_device *bdev;
5851+
struct bdev_handle *bdev_handle;
58515852
int hblock, blocksize;
58525853
ext4_fsblk_t sb_block;
58535854
unsigned long offset;
@@ -5856,16 +5857,17 @@ static struct block_device *ext4_get_journal_blkdev(struct super_block *sb,
58565857

58575858
/* see get_tree_bdev why this is needed and safe */
58585859
up_write(&sb->s_umount);
5859-
bdev = blkdev_get_by_dev(j_dev, BLK_OPEN_READ | BLK_OPEN_WRITE, sb,
5860-
&fs_holder_ops);
5860+
bdev_handle = bdev_open_by_dev(j_dev, BLK_OPEN_READ | BLK_OPEN_WRITE,
5861+
sb, &fs_holder_ops);
58615862
down_write(&sb->s_umount);
5862-
if (IS_ERR(bdev)) {
5863+
if (IS_ERR(bdev_handle)) {
58635864
ext4_msg(sb, KERN_ERR,
58645865
"failed to open journal device unknown-block(%u,%u) %ld",
5865-
MAJOR(j_dev), MINOR(j_dev), PTR_ERR(bdev));
5866-
return ERR_CAST(bdev);
5866+
MAJOR(j_dev), MINOR(j_dev), PTR_ERR(bdev_handle));
5867+
return bdev_handle;
58675868
}
58685869

5870+
bdev = bdev_handle->bdev;
58695871
blocksize = sb->s_blocksize;
58705872
hblock = bdev_logical_block_size(bdev);
58715873
if (blocksize < hblock) {
@@ -5912,12 +5914,12 @@ static struct block_device *ext4_get_journal_blkdev(struct super_block *sb,
59125914
*j_start = sb_block + 1;
59135915
*j_len = ext4_blocks_count(es);
59145916
brelse(bh);
5915-
return bdev;
5917+
return bdev_handle;
59165918

59175919
out_bh:
59185920
brelse(bh);
59195921
out_bdev:
5920-
blkdev_put(bdev, sb);
5922+
bdev_release(bdev_handle);
59215923
return ERR_PTR(errno);
59225924
}
59235925

@@ -5927,14 +5929,14 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb,
59275929
journal_t *journal;
59285930
ext4_fsblk_t j_start;
59295931
ext4_fsblk_t j_len;
5930-
struct block_device *journal_bdev;
5932+
struct bdev_handle *bdev_handle;
59315933
int errno = 0;
59325934

5933-
journal_bdev = ext4_get_journal_blkdev(sb, j_dev, &j_start, &j_len);
5934-
if (IS_ERR(journal_bdev))
5935-
return ERR_CAST(journal_bdev);
5935+
bdev_handle = ext4_get_journal_blkdev(sb, j_dev, &j_start, &j_len);
5936+
if (IS_ERR(bdev_handle))
5937+
return ERR_CAST(bdev_handle);
59365938

5937-
journal = jbd2_journal_init_dev(journal_bdev, sb->s_bdev, j_start,
5939+
journal = jbd2_journal_init_dev(bdev_handle->bdev, sb->s_bdev, j_start,
59385940
j_len, sb->s_blocksize);
59395941
if (IS_ERR(journal)) {
59405942
ext4_msg(sb, KERN_ERR, "failed to create device journal");
@@ -5949,14 +5951,14 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb,
59495951
goto out_journal;
59505952
}
59515953
journal->j_private = sb;
5952-
EXT4_SB(sb)->s_journal_bdev = journal_bdev;
5954+
EXT4_SB(sb)->s_journal_bdev_handle = bdev_handle;
59535955
ext4_init_journal_params(sb, journal);
59545956
return journal;
59555957

59565958
out_journal:
59575959
jbd2_journal_destroy(journal);
59585960
out_bdev:
5959-
blkdev_put(journal_bdev, sb);
5961+
bdev_release(bdev_handle);
59605962
return ERR_PTR(errno);
59615963
}
59625964

@@ -7300,12 +7302,12 @@ static inline int ext3_feature_set_ok(struct super_block *sb)
73007302
static void ext4_kill_sb(struct super_block *sb)
73017303
{
73027304
struct ext4_sb_info *sbi = EXT4_SB(sb);
7303-
struct block_device *journal_bdev = sbi ? sbi->s_journal_bdev : NULL;
7305+
struct bdev_handle *handle = sbi ? sbi->s_journal_bdev_handle : NULL;
73047306

73057307
kill_block_super(sb);
73067308

7307-
if (journal_bdev)
7308-
blkdev_put(journal_bdev, sb);
7309+
if (handle)
7310+
bdev_release(handle);
73097311
}
73107312

73117313
static struct file_system_type ext4_fs_type = {

0 commit comments

Comments
 (0)