diff mbox series

[4/7,v2] lib: remove e2fsck context from bh emulation

Message ID 20230919090227.25363-4-adilger@dilger.ca
State New
Headers show
Series [1/7,v2] lib: move jfs_user.h into libsupport | expand

Commit Message

Andreas Dilger Sept. 19, 2023, 9:02 a.m. UTC
From: Alexey Lyashkov <alexey.lyashkov@gmail.com>

In order to generalize journal handing, remove the e2fsck
context from generic structures like buffer_head, and device.
But fast commit code wants an e2fsck context as well, so move
the context pointer to journal struct.

Signed-off-by: Alexey Lyashkov <alexey.lyashkov@gmail.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
---
 e2fsck/journal.c        | 46 ++++++++++++++++++++---------------------
 lib/ext2fs/jfs_compat.h |  2 ++
 lib/support/jbd2_user.h | 12 -----------
 3 files changed, 25 insertions(+), 35 deletions(-)
diff mbox series

Patch

diff --git a/e2fsck/journal.c b/e2fsck/journal.c
index 367ec31d..d6129ed1 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -58,7 +58,7 @@  int jbd2_journal_bmap(journal_t *journal, unsigned long block,
 		return 0;
 	}
 
-	retval= ext2fs_bmap2(inode->i_ctx->fs, inode->i_ino,
+	retval= ext2fs_bmap2(inode->i_fs, inode->i_ino,
 			     &inode->i_ext2, NULL, 0, (blk64_t) block,
 			     0, &pblk);
 	*phys = pblk;
@@ -70,11 +70,12 @@  struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
 			   int blocksize)
 {
 	struct buffer_head *bh;
-	int bufsize = sizeof(*bh) + kdev->k_ctx->fs->blocksize -
+	int bufsize = sizeof(*bh) + kdev->k_fs->blocksize -
 		sizeof(bh->b_data);
+	errcode_t retval;
 
-	bh = e2fsck_allocate_memory(kdev->k_ctx, bufsize, "block buffer");
-	if (!bh)
+	retval = ext2fs_get_memzero(bufsize, &bh);
+	if (retval)
 		return NULL;
 
 	if (journal_enable_debug >= 3)
@@ -82,11 +83,11 @@  struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
 	jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n",
 		  blocknr, blocksize, bh_count);
 
-	bh->b_ctx = kdev->k_ctx;
+	bh->b_fs = kdev->k_fs;
 	if (kdev->k_dev == K_DEV_FS)
-		bh->b_io = kdev->k_ctx->fs->io;
+		bh->b_io = kdev->k_fs->io;
 	else
-		bh->b_io = kdev->k_ctx->fs->journal_io;
+		bh->b_io = kdev->k_fs->journal_io;
 	bh->b_size = blocksize;
 	bh->b_blocknr = blocknr;
 
@@ -98,9 +99,9 @@  int sync_blockdev(kdev_t kdev)
 	io_channel	io;
 
 	if (kdev->k_dev == K_DEV_FS)
-		io = kdev->k_ctx->fs->io;
+		io = kdev->k_fs->io;
 	else
-		io = kdev->k_ctx->fs->journal_io;
+		io = kdev->k_fs->journal_io;
 
 	return io_channel_flush(io) ? -EIO : 0;
 }
@@ -120,7 +121,7 @@  void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
 						     bh->b_blocknr,
 						     1, bh->b_data);
 			if (retval) {
-				com_err(bh->b_ctx->device_name, retval,
+				com_err(bh->b_fs->device_name, retval,
 					"while reading block %llu\n",
 					bh->b_blocknr);
 				bh->b_err = (int) retval;
@@ -135,7 +136,7 @@  void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
 						      bh->b_blocknr,
 						      1, bh->b_data);
 			if (retval) {
-				com_err(bh->b_ctx->device_name, retval,
+				com_err(bh->b_fs->device_name, retval,
 					"while writing block %llu\n",
 					bh->b_blocknr);
 				bh->b_err = (int) retval;
@@ -223,7 +224,7 @@  static int process_journal_block(ext2_filsys fs,
 static int ext4_fc_replay_scan(journal_t *j, struct buffer_head *bh,
 				int off, tid_t expected_tid)
 {
-	e2fsck_t ctx = j->j_fs_dev->k_ctx;
+	e2fsck_t ctx = j->j_ctx;
 	struct e2fsck_fc_replay_state *state;
 	int ret = JBD2_FC_REPLAY_CONTINUE;
 	struct ext4_fc_add_range ext;
@@ -805,7 +806,7 @@  static int ext4_fc_handle_del_range(e2fsck_t ctx, __u8 *val)
 static int ext4_fc_replay(journal_t *journal, struct buffer_head *bh,
 				enum passtype pass, int off, tid_t expected_tid)
 {
-	e2fsck_t ctx = journal->j_fs_dev->k_ctx;
+	e2fsck_t ctx = journal->j_ctx;
 	struct e2fsck_fc_replay_state *state = &ctx->fc_replay_state;
 	int ret = JBD2_FC_REPLAY_CONTINUE;
 	struct ext4_fc_tl tl;
@@ -933,10 +934,11 @@  static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
 	}
 	dev_journal = dev_fs+1;
 
-	dev_fs->k_ctx = dev_journal->k_ctx = ctx;
+	dev_fs->k_fs = dev_journal->k_fs = ctx->fs;
 	dev_fs->k_dev = K_DEV_FS;
 	dev_journal->k_dev = K_DEV_JOURNAL;
 
+	journal->j_ctx = ctx;
 	journal->j_dev = dev_journal;
 	journal->j_fs_dev = dev_fs;
 	journal->j_inode = NULL;
@@ -961,7 +963,7 @@  static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
 			goto errout;
 		}
 
-		j_inode->i_ctx = ctx;
+		j_inode->i_fs = ctx->fs;
 		j_inode->i_ino = sb->s_journal_inum;
 
 		if ((retval = ext2fs_read_inode(ctx->fs,
@@ -1203,9 +1205,8 @@  static errcode_t e2fsck_journal_fix_bad_inode(e2fsck_t ctx,
 }
 
 #define V1_SB_SIZE	0x0024
-static void clear_v2_journal_fields(journal_t *journal)
+static void clear_v2_journal_fields(e2fsck_t ctx, journal_t *journal)
 {
-	e2fsck_t ctx = journal->j_dev->k_ctx;
 	struct problem_context pctx;
 
 	clear_problem_context(&pctx);
@@ -1220,9 +1221,8 @@  static void clear_v2_journal_fields(journal_t *journal)
 }
 
 
-static errcode_t e2fsck_journal_load(journal_t *journal)
+static errcode_t e2fsck_journal_load(e2fsck_t ctx, journal_t *journal)
 {
-	e2fsck_t ctx = journal->j_dev->k_ctx;
 	journal_superblock_t *jsb;
 	struct buffer_head *jbh = journal->j_sb_buffer;
 	struct problem_context pctx;
@@ -1248,14 +1248,14 @@  static errcode_t e2fsck_journal_load(journal_t *journal)
 		    jsb->s_feature_incompat ||
 		    jsb->s_feature_ro_compat ||
 		    jsb->s_nr_users)
-			clear_v2_journal_fields(journal);
+			clear_v2_journal_fields(ctx, journal);
 		break;
 
 	case JBD2_SUPERBLOCK_V2:
 		journal->j_format_version = 2;
 		if (ntohl(jsb->s_nr_users) > 1 &&
 		    uuid_is_null(ctx->fs->super->s_journal_uuid))
-			clear_v2_journal_fields(journal);
+			clear_v2_journal_fields(ctx, journal);
 		if (ntohl(jsb->s_nr_users) > 1) {
 			fix_problem(ctx, PR_0_JOURNAL_UNSUPP_MULTIFS, &pctx);
 			return EXT2_ET_JOURNAL_UNSUPP_VERSION;
@@ -1442,7 +1442,7 @@  errcode_t e2fsck_check_ext3_journal(e2fsck_t ctx)
 		return retval;
 	}
 
-	retval = e2fsck_journal_load(journal);
+	retval = e2fsck_journal_load(ctx, journal);
 	if (retval) {
 		if ((retval == EXT2_ET_CORRUPT_JOURNAL_SB) ||
 		    ((retval == EXT2_ET_UNSUPP_FEATURE) &&
@@ -1560,7 +1560,7 @@  static errcode_t recover_ext3_journal(e2fsck_t ctx)
 	if (retval)
 		return retval;
 
-	retval = e2fsck_journal_load(journal);
+	retval = e2fsck_journal_load(ctx, journal);
 	if (retval)
 		goto errout;
 
diff --git a/lib/ext2fs/jfs_compat.h b/lib/ext2fs/jfs_compat.h
index 0e96b56c..938ee600 100644
--- a/lib/ext2fs/jfs_compat.h
+++ b/lib/ext2fs/jfs_compat.h
@@ -37,6 +37,7 @@  typedef struct kdev_s *kdev_t;
 
 struct buffer_head;
 struct inode;
+struct e2fsck_struct;
 
 typedef unsigned int gfp_t;
 #define GFP_KERNEL	0
@@ -94,6 +95,7 @@  struct journal_s
 	struct jbd2_revoke_table_s *j_revoke_table[2];
 	tid_t			j_failed_commit;
 	__u32			j_csum_seed;
+	struct e2fsck_struct *	j_ctx;
 	int (*j_fc_replay_callback)(struct journal_s *journal,
 				    struct buffer_head *bh,
 				    enum passtype pass, int off,
diff --git a/lib/support/jbd2_user.h b/lib/support/jbd2_user.h
index e4316f58..73473663 100644
--- a/lib/support/jbd2_user.h
+++ b/lib/support/jbd2_user.h
@@ -41,11 +41,7 @@ 
 #endif
 
 struct buffer_head {
-#ifdef DEBUGFS
 	ext2_filsys	b_fs;
-#else
-	e2fsck_t	b_ctx;
-#endif
 	io_channel	b_io;
 	int		b_size;
 	int		b_err;
@@ -56,21 +52,13 @@  struct buffer_head {
 };
 
 struct inode {
-#ifdef DEBUGFS
 	ext2_filsys	i_fs;
-#else
-	e2fsck_t	i_ctx;
-#endif
 	ext2_ino_t	i_ino;
 	struct ext2_inode i_ext2;
 };
 
 struct kdev_s {
-#ifdef DEBUGFS
 	ext2_filsys	k_fs;
-#else
-	e2fsck_t	k_ctx;
-#endif
 	int		k_dev;
 };