All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Al Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>
Cc: Namjae Jeon <linkinjeon@kernel.org>,
	Sungjong Seo <sj1557.seo@samsung.com>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
	"Darrick J. Wong" <djwong@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
	ntfs3@lists.linux.dev, linux-xfs@vger.kernel.org
Subject: [PATCH 08/13] ext4: close the external journal device in ->kill_sb
Date: Tue,  8 Aug 2023 09:15:55 -0700	[thread overview]
Message-ID: <20230808161600.1099516-9-hch@lst.de> (raw)
In-Reply-To: <20230808161600.1099516-1-hch@lst.de>

blkdev_put must not be called under sb->s_umount to avoid a lock order
reversal with disk->open_mutex.  Move closing the external journal device
into ->kill_sb to archive that.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/ext4/super.c | 50 ++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 063832e2d12a8e..0511fffb59b40d 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -93,6 +93,7 @@ static int ext4_get_tree(struct fs_context *fc);
 static int ext4_reconfigure(struct fs_context *fc);
 static void ext4_fc_free(struct fs_context *fc);
 static int ext4_init_fs_context(struct fs_context *fc);
+static void ext4_kill_sb(struct super_block *sb);
 static const struct fs_parameter_spec ext4_param_specs[];
 
 /*
@@ -135,7 +136,7 @@ static struct file_system_type ext2_fs_type = {
 	.name			= "ext2",
 	.init_fs_context	= ext4_init_fs_context,
 	.parameters		= ext4_param_specs,
-	.kill_sb		= kill_block_super,
+	.kill_sb		= ext4_kill_sb,
 	.fs_flags		= FS_REQUIRES_DEV,
 };
 MODULE_ALIAS_FS("ext2");
@@ -151,7 +152,7 @@ static struct file_system_type ext3_fs_type = {
 	.name			= "ext3",
 	.init_fs_context	= ext4_init_fs_context,
 	.parameters		= ext4_param_specs,
-	.kill_sb		= kill_block_super,
+	.kill_sb		= ext4_kill_sb,
 	.fs_flags		= FS_REQUIRES_DEV,
 };
 MODULE_ALIAS_FS("ext3");
@@ -1116,25 +1117,6 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
 	return NULL;
 }
 
-/*
- * Release the journal device
- */
-static void ext4_blkdev_remove(struct ext4_sb_info *sbi)
-{
-	struct block_device *bdev;
-	bdev = sbi->s_journal_bdev;
-	if (bdev) {
-		/*
-		 * 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;
-	}
-}
-
 static inline struct inode *orphan_list_entry(struct list_head *l)
 {
 	return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode;
@@ -1330,8 +1312,13 @@ static void ext4_put_super(struct super_block *sb)
 	sync_blockdev(sb->s_bdev);
 	invalidate_bdev(sb->s_bdev);
 	if (sbi->s_journal_bdev) {
+		/*
+		 * 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.
+		 */
 		sync_blockdev(sbi->s_journal_bdev);
-		ext4_blkdev_remove(sbi);
+		invalidate_bdev(sbi->s_journal_bdev);
 	}
 
 	ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
@@ -5655,9 +5642,11 @@ failed_mount9: __maybe_unused
 		kfree(get_qf_name(sb, sbi, i));
 #endif
 	fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
-	/* ext4_blkdev_remove() calls kill_bdev(), release bh before it. */
 	brelse(sbi->s_sbh);
-	ext4_blkdev_remove(sbi);
+	if (sbi->s_journal_bdev) {
+		invalidate_bdev(sbi->s_journal_bdev);
+		blkdev_put(sbi->s_journal_bdev, sb);
+	}
 out_fail:
 	invalidate_bdev(sb->s_bdev);
 	sb->s_fs_info = NULL;
@@ -7267,12 +7256,23 @@ static inline int ext3_feature_set_ok(struct super_block *sb)
 	return 1;
 }
 
+static void ext4_kill_sb(struct super_block *sb)
+{
+	struct ext4_sb_info *sbi = EXT4_SB(sb);
+	struct block_device *journal_bdev = sbi ? sbi->s_journal_bdev : NULL;
+
+	kill_block_super(sb);
+
+	if (journal_bdev)
+		blkdev_put(journal_bdev, sb);
+}
+
 static struct file_system_type ext4_fs_type = {
 	.owner			= THIS_MODULE,
 	.name			= "ext4",
 	.init_fs_context	= ext4_init_fs_context,
 	.parameters		= ext4_param_specs,
-	.kill_sb		= kill_block_super,
+	.kill_sb		= ext4_kill_sb,
 	.fs_flags		= FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
 };
 MODULE_ALIAS_FS("ext4");
-- 
2.39.2


  parent reply	other threads:[~2023-08-08 19:59 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-08 16:15 s_fs_info and ->kill_sb revisited Christoph Hellwig
2023-08-08 16:15 ` [PATCH 01/13] xfs: reformat the xfs_fs_free prototype Christoph Hellwig
2023-08-08 16:54   ` Darrick J. Wong
2023-08-08 16:15 ` [PATCH 02/13] xfs: remove a superflous s_fs_info NULL check in xfs_fs_put_super Christoph Hellwig
2023-08-09  7:28   ` Christian Brauner
2023-08-09 15:29   ` Darrick J. Wong
2023-08-08 16:15 ` [PATCH 03/13] xfs: free the mount in ->kill_sb Christoph Hellwig
2023-08-09  7:38   ` Christian Brauner
2023-08-09 16:26     ` Christoph Hellwig
2023-08-09 15:38   ` Darrick J. Wong
2023-08-08 16:15 ` [PATCH 04/13] xfs: remove xfs_blkdev_put Christoph Hellwig
2023-08-09  7:40   ` Christian Brauner
2023-08-09 15:39   ` Darrick J. Wong
2023-08-08 16:15 ` [PATCH 05/13] xfs: don't call invalidate_bdev in xfs_free_buftarg Christoph Hellwig
2023-08-08 19:13   ` Darrick J. Wong
2023-08-08 16:15 ` [PATCH 06/13] xfs: close the RT and log block devices " Christoph Hellwig
2023-08-09 15:45   ` Darrick J. Wong
2023-08-09 16:17     ` Christoph Hellwig
2023-08-08 16:15 ` [PATCH 07/13] xfs: close the external block devices in xfs_mount_free Christoph Hellwig
2023-08-09 15:55   ` Darrick J. Wong
2023-08-09 16:14     ` Christoph Hellwig
2023-08-09 17:17       ` Darrick J. Wong
2023-08-08 16:15 ` Christoph Hellwig [this message]
2023-08-08 16:15 ` [PATCH 09/13] exfat: don't RCU-free the sbi Christoph Hellwig
2023-08-08 16:15 ` [PATCH 10/13] exfat: free the sbi and iocharset in ->kill_sb Christoph Hellwig
2023-08-08 16:15 ` [PATCH 11/13] ntfs3: rename put_ntfs ntfs3_free_sbi Christoph Hellwig
2023-08-09  7:56   ` Christian Brauner
2023-08-08 16:15 ` [PATCH 12/13] ntfs3: don't call sync_blockdev in ntfs_put_super Christoph Hellwig
2023-08-09  7:57   ` Christian Brauner
2023-08-08 16:16 ` [PATCH 13/13] ntfs3: free the sbi in ->kill_sb Christoph Hellwig
2023-08-09  7:55   ` Christian Brauner
  -- strict thread matches above, loose matches on Subject: below --
2023-08-09 22:05 s_fs_info and ->kill_sb revisited v2 Christoph Hellwig
2023-08-09 22:05 ` [PATCH 08/13] ext4: close the external journal device in ->kill_sb Christoph Hellwig

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=20230808161600.1099516-9-hch@lst.de \
    --to=hch@lst.de \
    --cc=adilger.kernel@dilger.ca \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=brauner@kernel.org \
    --cc=djwong@kernel.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    --cc=sj1557.seo@samsung.com \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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.