Skip to contentSkip to conversation

remove bdev->bd_super

PATCH In review Christoph Hellwig 4 participants 9 messages Aug 7, 2023 – Aug 8, 2023

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

Hi all,

this series is against the vfs.super branch in the VFS tree and removes the bd_super field in struct block_device.

Diffstat:

 fs/buffer.c               |   11 +++--------
 fs/ext4/ext4_jbd2.c       |    3 +--
 fs/ext4/super.c           |    1 -
 fs/ocfs2/journal.c        |    6 +++---
 fs/romfs/super.c          |    1 -
 fs/super.c                |    3 ---
 include/linux/blk_types.h |    1 -
 7 files changed, 7 insertions(+), 19 deletions(-)
#1 lore raw

PATCH 1/4 fs: stop using bdev->bd_super in mark_buffer_write_io_error

bdev->bd_super is a somewhat awkward backpointer from a block device to an owning file system with unclear rules.

For the buffer_head code we already have a good backpointer for the inode that the buffer_head is associated with, even if it lives on the block device mapping: b_assoc_map. It is used track dirty buffers associated with an inode but living on the block device mapping like directory buffers in ext4.

mark_buffer_write_io_error already uses it for the call to mapping_set_error, and should be doing the same for the per-sb error sequence.

---
 fs/buffer.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
fs/buffer.c +3 -8
index bd091329026c0f..f36ef03c078af6 100644
@@ -1225,19 +1225,14 @@ EXPORT_SYMBOL(mark_buffer_dirty);
 
 void mark_buffer_write_io_error(struct buffer_head *bh)
 {
-	struct super_block *sb;
-
 	set_buffer_write_io_error(bh);
 	/* FIXME: do we need to set this in both places? */
 	if (bh->b_folio && bh->b_folio->mapping)
 		mapping_set_error(bh->b_folio->mapping, -EIO);
-	if (bh->b_assoc_map)
+	if (bh->b_assoc_map) {
 		mapping_set_error(bh->b_assoc_map, -EIO);
-	rcu_read_lock();
-	sb = READ_ONCE(bh->b_bdev->bd_super);
-	if (sb)
-		errseq_set(&sb->s_wb_err, -EIO);
-	rcu_read_unlock();
+		errseq_set(&bh->b_assoc_map->host->i_sb->s_wb_err, -EIO);
+	}
 }
 EXPORT_SYMBOL(mark_buffer_write_io_error);
 
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/4 ext4: don't use bdev->bd_super in __ext4_journal_get_write_access

In reply to Christoph Hellwig

__ext4_journal_get_write_access already has a super_block available, and there is no need to go from that to the bdev to go back to the owning super_block.

---
 fs/ext4/ext4_jbd2.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/ext4_jbd2.c +1 -2
index 77f318ec8abb78..b38d59581411c0 100644
@@ -234,8 +234,7 @@ int __ext4_journal_get_write_access(const char *where, unsigned int line,
 
 	might_sleep();
 
-	if (bh->b_bdev->bd_super)
-		ext4_check_bdev_write_error(bh->b_bdev->bd_super);
+	ext4_check_bdev_write_error(sb);
 
 	if (ext4_handle_valid(handle)) {
 		err = jbd2_journal_get_write_access(handle, bh);
Signature · 1 line
2.39.2
#4 lore raw

PATCH 3/4 ocfs2: stop using bdev->bd_super for journal error logging

In reply to Christoph Hellwig

All ocfs2 journal error handling and logging is based on buffer_heads, and the owning inode and thus super_block can be retrieved through bh->b_assoc_map->host. Switch to using that to remove the last users of bdev->bd_super.

---
 fs/ocfs2/journal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ocfs2/journal.c +3 -3
index 25d8072ccfce46..c19c730c26e270 100644
@@ -557,7 +557,7 @@ static void ocfs2_abort_trigger(struct jbd2_buffer_trigger_type *triggers,
 	     (unsigned long)bh,
 	     (unsigned long long)bh->b_blocknr);
 
-	ocfs2_error(bh->b_bdev->bd_super,
+	ocfs2_error(bh->b_assoc_map->host->i_sb,
 		    "JBD2 has aborted our journal, ocfs2 cannot continue\n");
 }
 
@@ -780,14 +780,14 @@ void ocfs2_journal_dirty(handle_t *handle, struct buffer_head *bh)
 		mlog_errno(status);
 		if (!is_handle_aborted(handle)) {
 			journal_t *journal = handle->h_transaction->t_journal;
-			struct super_block *sb = bh->b_bdev->bd_super;
 
 			mlog(ML_ERROR, "jbd2_journal_dirty_metadata failed. "
 					"Aborting transaction and journal.\n");
 			handle->h_err = status;
 			jbd2_journal_abort_handle(handle);
 			jbd2_journal_abort(journal, status);
-			ocfs2_abort(sb, "Journal already aborted.\n");
+			ocfs2_abort(bh->b_assoc_map->host->i_sb,
+				    "Journal already aborted.\n");
 		}
 	}
 }
Signature · 1 line
2.39.2
maintainer Acked-by on v1 3/4
#5 lore raw

Re: [PATCH 3/4] ocfs2: stop using bdev->bd_super for journal error logging

Quoted 6 lines · Christoph Hellwig

All ocfs2 journal error handling and logging is based on buffer_heads, and the owning inode and thus super_block can be retrieved through bh->b_assoc_map->host. Switch to using that to remove the last users of bdev->bd_super.

Looks fine.

Quoted 34 lines
---
 fs/ocfs2/journal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ocfs2/journal.c +3 -3
index 25d8072ccfce46..c19c730c26e270 100644
@@ -557,7 +557,7 @@ static void ocfs2_abort_trigger(struct jbd2_buffer_trigger_type *triggers,
 	     (unsigned long)bh,
 	     (unsigned long long)bh->b_blocknr);
 
-	ocfs2_error(bh->b_bdev->bd_super,
+	ocfs2_error(bh->b_assoc_map->host->i_sb,
 		    "JBD2 has aborted our journal, ocfs2 cannot continue\n");
 }
 
@@ -780,14 +780,14 @@ void ocfs2_journal_dirty(handle_t *handle, struct buffer_head *bh)
 		mlog_errno(status);
 		if (!is_handle_aborted(handle)) {
 			journal_t *journal = handle->h_transaction->t_journal;
-			struct super_block *sb = bh->b_bdev->bd_super;
 
 			mlog(ML_ERROR, "jbd2_journal_dirty_metadata failed. "
 					"Aborting transaction and journal.\n");
 			handle->h_err = status;
 			jbd2_journal_abort_handle(handle);
 			jbd2_journal_abort(journal, status);
-			ocfs2_abort(sb, "Journal already aborted.\n");
+			ocfs2_abort(bh->b_assoc_map->host->i_sb,
+				    "Journal already aborted.\n");
 		}
 	}
 }
#6 lore raw

PATCH 4/4 fs, block: remove bdev->bd_super

In reply to Christoph Hellwig

bdev->bd_super is unused now, remove it.

---
 fs/cramfs/inode.c         | 1 -
 fs/ext4/super.c           | 1 -
 fs/romfs/super.c          | 1 -
 fs/super.c                | 3 ---
 include/linux/blk_types.h | 1 -
 5 files changed, 7 deletions(-)
fs/cramfs/inode.c +0 -1
index d2eea2e4807c4f..569f88dcb2f12c 100644
@@ -493,7 +493,6 @@ static void cramfs_kill_sb(struct super_block *sb)
 		put_mtd_device(sb->s_mtd);
 		sb->s_mtd = NULL;
 	} else if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV) && sb->s_bdev) {
-		sb->s_bdev->bd_super = NULL;
 		sync_blockdev(sb->s_bdev);
 		blkdev_put(sb->s_bdev, sb);
 	}
fs/ext4/super.c +0 -1
index 063832e2d12a8e..e6384782b4d036 100644
@@ -5563,7 +5563,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 	spin_lock_init(&sbi->s_bdev_wb_lock);
 	errseq_check_and_advance(&sb->s_bdev->bd_inode->i_mapping->wb_err,
 				 &sbi->s_bdev_wb_err);
-	sb->s_bdev->bd_super = sb;
 	EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
 	ext4_orphan_cleanup(sb, es);
 	EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
fs/romfs/super.c +0 -1
index b9eded546259bc..22cdb9a86a5748 100644
@@ -593,7 +593,6 @@ static void romfs_kill_sb(struct super_block *sb)
 #endif
 #ifdef CONFIG_ROMFS_ON_BLOCK
 	if (sb->s_bdev) {
-		sb->s_bdev->bd_super = NULL;
 		sync_blockdev(sb->s_bdev);
 		blkdev_put(sb->s_bdev, sb);
 	}
fs/super.c +0 -3
index efa28679e3e5b3..0023685815fda0 100644
@@ -1369,7 +1369,6 @@ int get_tree_bdev(struct fs_context *fc,
 			return error;
 		}
 		s->s_flags |= SB_ACTIVE;
-		s->s_bdev->bd_super = s;
 	}
 
 	BUG_ON(fc->root);
@@ -1423,7 +1422,6 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,
 		}
 
 		s->s_flags |= SB_ACTIVE;
-		s->s_bdev->bd_super = s;
 	}
 
 	return dget(s->s_root);
@@ -1436,7 +1434,6 @@ void kill_block_super(struct super_block *sb)
 
 	generic_shutdown_super(sb);
 	if (bdev) {
-		bdev->bd_super = NULL;
 		sync_blockdev(bdev);
 		blkdev_put(bdev, sb);
 	}
include/linux/blk_types.h +0 -1
index 0bad62cca3d025..d5c5e59ddbd25a 100644
@@ -52,7 +52,6 @@ struct block_device {
 	atomic_t		bd_openers;
 	spinlock_t		bd_size_lock; /* for bd_inode->i_size updates */
 	struct inode *		bd_inode;	/* will die */
-	struct super_block *	bd_super;
 	void *			bd_claiming;
 	void *			bd_holder;
 	const struct blk_holder_ops *bd_holder_ops;
Signature · 1 line
2.39.2
maintainer Applied
#8 lore raw
In reply to Christoph Hellwig
Quoted 13 lines · Christoph Hellwig

this series is against the vfs.super branch in the VFS tree and removes the bd_super field in struct block_device.

Diffstat:

 fs/buffer.c               |   11 +++--------
 fs/ext4/ext4_jbd2.c       |    3 +--
 fs/ext4/super.c           |    1 -
 fs/ocfs2/journal.c        |    6 +++---
 fs/romfs/super.c          |    1 -
 fs/super.c                |    3 ---
 include/linux/blk_types.h |    1 -
 7 files changed, 7 insertions(+), 19 deletions(-)
Quoted 1 line

[...]

Applied to the vfs.super branch of the vfs/vfs.git tree. Patches in the vfs.super branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.super

[1/4] fs: stop using bdev->bd_super in mark_buffer_write_io_error

      https://git.kernel.org/vfs/vfs/c/0007ce9af88c
[2/4] ext4: don't use bdev->bd_super in __ext4_journal_get_write_access
      https://git.kernel.org/vfs/vfs/c/a9572cf0e7d2
[3/4] ocfs2: stop using bdev->bd_super for journal error logging
      https://git.kernel.org/vfs/vfs/c/807c772f2a12
[4/4] fs, block: remove bdev->bd_super
      https://git.kernel.org/vfs/vfs/c/0a59ff894703