lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DF14E0DC-0B1B-47F6-841B-A17CCB141878@dilger.ca>
Date:   Mon, 18 Sep 2023 17:57:30 -0600
From:   Andreas Dilger <adilger@...ger.ca>
To:     Alexey Lyashkov <alexey.lyashkov@...il.com>
Cc:     linux-ext4@...r.kernel.org, Theodore Ts'o <tytso@....edu>,
        Artem Blagodarenko <artem.blagodarenko@...il.com>
Subject: Re: [PATCH 4/5] remove an e2fsck context from bh emulation code.

On Aug 4, 2022, at 3:56 AM, Alexey Lyashkov <alexey.lyashkov@...il.com> wrote:
> 
> In order to generalize a journal handing, remove a e2fsck context
> from generic structures like buffer_head, and device.
> But fast commit code want a e2fsck context as well, so move it pointer
> to journal struct.

Missing Signed-off-by: line.

Reviewed-by: Andreas Dilger <adilger@...ger.ca>

> ---
> e2fsck/journal.c        | 46 ++++++++++++++++++++---------------------
> lib/ext2fs/jfs_compat.h |  2 ++
> lib/support/jfs_user.h  | 12 -----------
> 3 files changed, 25 insertions(+), 35 deletions(-)
> 
> diff --git a/e2fsck/journal.c b/e2fsck/journal.c
> index 682d82a4..728f5a24 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;
> @@ -796,7 +797,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;
> @@ -924,10 +925,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;
> @@ -945,7 +947,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,
> @@ -1186,9 +1188,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);
> @@ -1203,9 +1204,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;
> @@ -1231,14 +1231,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;
> @@ -1425,7 +1425,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) &&
> @@ -1543,7 +1543,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 e11cf494..bfafae12 100644
> --- a/lib/ext2fs/jfs_compat.h
> +++ b/lib/ext2fs/jfs_compat.h
> @@ -41,6 +41,7 @@ typedef struct kdev_s *kdev_t;
> 
> struct buffer_head;
> struct inode;
> +struct e2fsck_struct;
> 
> typedef unsigned int gfp_t;
> #define GFP_KERNEL	0
> @@ -98,6 +99,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/jfs_user.h b/lib/support/jfs_user.h
> index b9c2fa54..bb392811 100644
> --- a/lib/support/jfs_user.h
> +++ b/lib/support/jfs_user.h
> @@ -40,11 +40,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;
> @@ -55,21 +51,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;
> };
> 
> --
> 2.31.1
> 


Cheers, Andreas






Download attachment "signature.asc" of type "application/pgp-signature" (874 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ