All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: <linux-fsdevel@vger.kernel.org>
Cc: <linux-block@vger.kernel.org>,
	Christoph Hellwig <hch@infradead.org>, Jan Kara <jack@suse.cz>,
	linux-ext4@vger.kernel.org, Ted Tso <tytso@mit.edu>
Subject: [PATCH 22/29] ext4: Convert to bdev_open_by_dev()
Date: Fri, 11 Aug 2023 13:04:53 +0200	[thread overview]
Message-ID: <20230811110504.27514-22-jack@suse.cz> (raw)
In-Reply-To: <20230810171429.31759-1-jack@suse.cz>

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>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/ext4.h  |  2 +-
 fs/ext4/fsmap.c |  9 +++++----
 fs/ext4/super.c | 40 ++++++++++++++++++++--------------------
 3 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 1e2259d9967d..6856e80abf70 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1541,7 +1541,7 @@ struct ext4_sb_info {
 	unsigned long s_commit_interval;
 	u32 s_max_batch_time;
 	u32 s_min_batch_time;
-	struct block_device *s_journal_bdev;
+	struct bdev_handle *s_journal_bdev_handle;
 #ifdef CONFIG_QUOTA
 	/* Names of quota files with journalled quota */
 	char __rcu *s_qf_names[EXT4_MAXQUOTAS];
diff --git a/fs/ext4/fsmap.c b/fs/ext4/fsmap.c
index cdf9bfe10137..11e6f33677a2 100644
--- a/fs/ext4/fsmap.c
+++ b/fs/ext4/fsmap.c
@@ -576,8 +576,9 @@ static bool ext4_getfsmap_is_valid_device(struct super_block *sb,
 	if (fm->fmr_device == 0 || fm->fmr_device == UINT_MAX ||
 	    fm->fmr_device == new_encode_dev(sb->s_bdev->bd_dev))
 		return true;
-	if (EXT4_SB(sb)->s_journal_bdev &&
-	    fm->fmr_device == new_encode_dev(EXT4_SB(sb)->s_journal_bdev->bd_dev))
+	if (EXT4_SB(sb)->s_journal_bdev_handle &&
+	    fm->fmr_device ==
+	    new_encode_dev(EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev))
 		return true;
 	return false;
 }
@@ -647,9 +648,9 @@ int ext4_getfsmap(struct super_block *sb, struct ext4_fsmap_head *head,
 	memset(handlers, 0, sizeof(handlers));
 	handlers[0].gfd_dev = new_encode_dev(sb->s_bdev->bd_dev);
 	handlers[0].gfd_fn = ext4_getfsmap_datadev;
-	if (EXT4_SB(sb)->s_journal_bdev) {
+	if (EXT4_SB(sb)->s_journal_bdev_handle) {
 		handlers[1].gfd_dev = new_encode_dev(
-				EXT4_SB(sb)->s_journal_bdev->bd_dev);
+			EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev);
 		handlers[1].gfd_fn = ext4_getfsmap_logdev;
 	}
 
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 45fd5372bf8a..9ca3665e1b92 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1099,20 +1099,20 @@ void ext4_update_dynamic_rev(struct super_block *sb)
 /*
  * Open the external journal device
  */
-static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
+static struct bdev_handle *ext4_blkdev_get(dev_t dev, struct super_block *sb)
 {
-	struct block_device *bdev;
+	struct bdev_handle *handle;
 
-	bdev = blkdev_get_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_WRITE, sb,
-				 &fs_holder_ops);
-	if (IS_ERR(bdev))
+	handle = bdev_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_WRITE, sb,
+				  &fs_holder_ops);
+	if (IS_ERR(handle))
 		goto fail;
-	return bdev;
+	return handle;
 
 fail:
 	ext4_msg(sb, KERN_ERR,
 		 "failed to open journal device unknown-block(%u,%u) %ld",
-		 MAJOR(dev), MINOR(dev), PTR_ERR(bdev));
+		 MAJOR(dev), MINOR(dev), PTR_ERR(handle));
 	return NULL;
 }
 
@@ -1121,17 +1121,15 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
  */
 static void ext4_blkdev_remove(struct ext4_sb_info *sbi)
 {
-	struct block_device *bdev;
-	bdev = sbi->s_journal_bdev;
-	if (bdev) {
+	if (sbi->s_journal_bdev_handle) {
 		/*
 		 * Invalidate the journal device's buffers.  We don't want them
 		 * floating about in memory - the physical journal device may
 		 * hotswapped, and it breaks the `ro-after' testing code.
 		 */
-		invalidate_bdev(bdev);
-		blkdev_put(bdev, sbi->s_sb);
-		sbi->s_journal_bdev = NULL;
+		invalidate_bdev(sbi->s_journal_bdev_handle->bdev);
+		bdev_release(sbi->s_journal_bdev_handle);
+		sbi->s_journal_bdev_handle = NULL;
 	}
 }
 
@@ -1329,8 +1327,8 @@ static void ext4_put_super(struct super_block *sb)
 
 	sync_blockdev(sb->s_bdev);
 	invalidate_bdev(sb->s_bdev);
-	if (sbi->s_journal_bdev) {
-		sync_blockdev(sbi->s_journal_bdev);
+	if (sbi->s_journal_bdev_handle) {
+		sync_blockdev(sbi->s_journal_bdev_handle->bdev);
 		ext4_blkdev_remove(sbi);
 	}
 
@@ -4218,7 +4216,7 @@ int ext4_calculate_overhead(struct super_block *sb)
 	 * Add the internal journal blocks whether the journal has been
 	 * loaded or not
 	 */
-	if (sbi->s_journal && !sbi->s_journal_bdev)
+	if (sbi->s_journal && !sbi->s_journal_bdev_handle)
 		overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len);
 	else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) {
 		/* j_inum for internal journal is non-zero */
@@ -5840,17 +5838,19 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
 	unsigned long offset;
 	struct ext4_super_block *es;
 	struct block_device *bdev;
+	struct bdev_handle *bdev_handle;
 
 	if (WARN_ON_ONCE(!ext4_has_feature_journal(sb)))
 		return NULL;
 
 	/* see get_tree_bdev why this is needed and safe */
 	up_write(&sb->s_umount);
-	bdev = ext4_blkdev_get(j_dev, sb);
+	bdev_handle = ext4_blkdev_get(j_dev, sb);
 	down_write(&sb->s_umount);
-	if (bdev == NULL)
+	if (!bdev_handle)
 		return NULL;
 
+	bdev = bdev_handle->bdev;
 	blocksize = sb->s_blocksize;
 	hblock = bdev_logical_block_size(bdev);
 	if (blocksize < hblock) {
@@ -5914,14 +5914,14 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
 			be32_to_cpu(journal->j_superblock->s_nr_users));
 		goto out_journal;
 	}
-	EXT4_SB(sb)->s_journal_bdev = bdev;
+	EXT4_SB(sb)->s_journal_bdev_handle = bdev_handle;
 	ext4_init_journal_params(sb, journal);
 	return journal;
 
 out_journal:
 	jbd2_journal_destroy(journal);
 out_bdev:
-	blkdev_put(bdev, sb);
+	bdev_release(bdev_handle);
 	return NULL;
 }
 
-- 
2.35.3


  parent reply	other threads:[~2023-08-11 11:06 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-11 11:04 [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle Jan Kara
2023-08-11 11:04 ` Jan Kara
2023-08-11 11:04 ` [dm-devel] " Jan Kara
2023-08-11 11:04 ` Jan Kara
2023-08-11 11:04 ` Jan Kara
2023-08-11 11:04 ` [f2fs-dev] " Jan Kara
2023-08-11 11:04 ` [PATCH 01/29] block: Provide bdev_open_* functions Jan Kara
2023-08-11 11:04 ` [PATCH 02/29] block: Use bdev_open_by_dev() in blkdev_open() Jan Kara
2023-08-11 12:25   ` Christoph Hellwig
2023-08-14 13:51     ` Jan Kara
2023-08-25  1:14   ` Al Viro
2023-08-11 11:04 ` [PATCH 03/29] block: Use bdev_open_by_dev() in disk_scan_partitions() and blkdev_bszset() Jan Kara
2023-08-11 11:04 ` [PATCH 04/29] drdb: Convert to use bdev_open_by_path() Jan Kara
2023-08-11 11:04 ` [PATCH 05/29] pktcdvd: Convert to bdev_open_by_dev() Jan Kara
2023-08-11 11:04 ` [PATCH 06/29] rnbd-srv: Convert to use bdev_open_by_path() Jan Kara
2023-08-11 11:04 ` [PATCH 07/29] xen/blkback: Convert to bdev_open_by_dev() Jan Kara
2023-08-11 11:04 ` [PATCH 08/29] zram: Convert to use bdev_open_by_dev() Jan Kara
2023-08-11 11:04 ` [PATCH 09/29] bcache: Convert to bdev_open_by_path() Jan Kara
2023-08-21  1:06   ` Eric Wheeler
2023-08-21 17:50     ` Jan Kara
2023-08-21 18:54       ` Eric Wheeler
2023-08-23 10:10         ` Coly Li
2023-08-11 11:04 ` [PATCH 10/29] dm: Convert to bdev_open_by_dev() Jan Kara
2023-08-11 11:04   ` [dm-devel] " Jan Kara
2023-08-11 11:04 ` [PATCH 11/29] md: " Jan Kara
2023-08-13 15:54   ` Song Liu
2023-08-14 13:37     ` Jan Kara
2023-08-11 11:04 ` [PATCH 12/29] mtd: block2mtd: Convert to bdev_open_by_dev/path() Jan Kara
2023-08-11 11:04   ` Jan Kara
2023-08-11 11:04 ` [PATCH 13/29] nvmet: Convert to bdev_open_by_path() Jan Kara
2023-08-11 11:04 ` [PATCH 14/29] s390/dasd: " Jan Kara
2023-08-11 11:04 ` [PATCH 15/29] scsi: target: " Jan Kara
2023-08-11 11:04 ` [PATCH 16/29] PM: hibernate: Convert to bdev_open_by_dev() Jan Kara
2023-08-11 16:57   ` Rafael J. Wysocki
2023-08-11 11:04 ` [PATCH 17/29] PM: hibernate: Drop unused snapshot_test argument Jan Kara
2023-08-11 16:58   ` Rafael J. Wysocki
2023-08-11 11:04 ` [PATCH 18/29] mm/swap: Convert to use bdev_open_by_dev() Jan Kara
2023-08-11 11:04 ` [PATCH 19/29] fs: Convert to bdev_open_by_dev() Jan Kara
2023-08-11 11:04 ` [PATCH 20/29] btrfs: Convert to bdev_open_by_path() Jan Kara
2023-08-11 11:04 ` [PATCH 21/29] erofs: Convert to use bdev_open_by_path() Jan Kara
2023-08-11 11:04   ` Jan Kara
2023-08-11 11:04 ` Jan Kara [this message]
2023-08-11 11:04 ` [PATCH 23/29] f2fs: Convert to bdev_open_by_dev/path() Jan Kara
2023-08-11 11:04   ` [f2fs-dev] " Jan Kara
2023-08-11 11:04 ` [PATCH 24/29] jfs: Convert to bdev_open_by_dev() Jan Kara
2023-08-11 11:04 ` [PATCH 25/29] nfs/blocklayout: Convert to use bdev_open_by_dev/path() Jan Kara
2023-08-11 11:04 ` [PATCH 26/29] ocfs2: Convert to use bdev_open_by_dev() Jan Kara
2023-08-11 11:04 ` [PATCH 27/29] reiserfs: Convert to bdev_open_by_dev/path() Jan Kara
2023-08-11 11:04   ` Jan Kara
2023-08-11 11:04 ` [PATCH 28/29] xfs: Convert to bdev_open_by_path() Jan Kara
     [not found]   ` <CGME20230814102748eucas1p269b8a53ed09fae1eb57dce3d2a7de752@eucas1p2.samsung.com>
2023-08-14 10:27     ` Daniel Gomez
2023-08-14 13:43       ` Jan Kara
2023-08-11 11:05 ` [PATCH 29/29] block: Remove blkdev_get_by_*() functions Jan Kara
2023-08-11 12:27 ` [PATCH v2 0/29] block: Make blkdev_get_by_*() return handle Christoph Hellwig
2023-08-11 12:27   ` Christoph Hellwig
2023-08-11 12:27   ` Christoph Hellwig
2023-08-11 12:27   ` [dm-devel] " Christoph Hellwig
2023-08-11 12:27   ` Christoph Hellwig
2023-08-11 12:27   ` [f2fs-dev] " Christoph Hellwig
2023-08-25  1:58 ` Al Viro
2023-08-25  1:58   ` Al Viro
2023-08-25  1:58   ` Al Viro
2023-08-25  1:58   ` [dm-devel] " Al Viro
2023-08-25  1:58   ` [f2fs-dev] " Al Viro
2023-08-25  1:58   ` Al Viro
2023-08-25 13:47   ` Jan Kara
2023-08-25 13:47     ` Jan Kara
2023-08-25 13:47     ` [dm-devel] " Jan Kara
2023-08-25 13:47     ` Jan Kara
2023-08-25 13:47     ` Jan Kara
2023-08-25 13:47     ` [f2fs-dev] " Jan Kara
2023-08-26  2:28     ` Al Viro
2023-08-26  2:28       ` Al Viro
2023-08-26  2:28       ` [dm-devel] " Al Viro
2023-08-26  2:28       ` Al Viro
2023-08-26  2:28       ` Al Viro
2023-08-26  2:28       ` [f2fs-dev] " Al Viro
2023-08-28 14:27       ` Christoph Hellwig
2023-08-28 14:27         ` Christoph Hellwig
2023-08-28 14:27         ` [dm-devel] " Christoph Hellwig
2023-08-28 14:27         ` Christoph Hellwig
2023-08-28 14:27         ` Christoph Hellwig
2023-08-28 14:27         ` [f2fs-dev] " Christoph Hellwig
2023-08-28 13:20     ` Christian Brauner
2023-08-28 13:20       ` Christian Brauner
2023-08-28 13:20       ` [dm-devel] " Christian Brauner
2023-08-28 13:20       ` Christian Brauner
2023-08-28 13:20       ` Christian Brauner
2023-08-28 13:20       ` [f2fs-dev] " Christian Brauner
2023-08-28 14:22     ` Christoph Hellwig
2023-08-28 14:22       ` Christoph Hellwig
2023-08-28 14:22       ` [dm-devel] " Christoph Hellwig
2023-08-28 14:22       ` Christoph Hellwig
2023-08-28 14:22       ` Christoph Hellwig
2023-08-28 14:22       ` [f2fs-dev] " Christoph Hellwig
2023-08-23 10:48 [PATCH v3 " Jan Kara
2023-08-23 10:48 ` [PATCH 22/29] ext4: Convert to bdev_open_by_dev() Jan Kara
2023-08-25 12:29   ` Christian Brauner
2023-09-27  9:34 ` Jan Kara

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=20230811110504.27514-22-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.