public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Zhang Yi <yi.zhang@huaweicloud.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu,
	adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com,
	chengzhihao1@huawei.com, yukuai3@huawei.com
Subject: Re: [PATCH 12/12] ext4: ext4_get_{dev}_journal return proper error value
Date: Thu, 3 Aug 2023 18:19:07 +0200	[thread overview]
Message-ID: <20230803161907.dsug5kqmxvn25kkf@quack3> (raw)
In-Reply-To: <20230704134233.110812-13-yi.zhang@huaweicloud.com>

On Tue 04-07-23 21:42:33, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
> 
> ext4_get_journal() and ext4_get_dev_journal() return NULL if they failed
> to init journal, making them return proper error value instead, also
> rename them to ext4_open_{inode,dev}_journal().
> 
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>

Looks good to me. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/super.c | 51 +++++++++++++++++++++++++++++--------------------
>  1 file changed, 30 insertions(+), 21 deletions(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 25ae536a370f..ae8a964e493d 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -5752,18 +5752,18 @@ static struct inode *ext4_get_journal_inode(struct super_block *sb,
>  	journal_inode = ext4_iget(sb, journal_inum, EXT4_IGET_SPECIAL);
>  	if (IS_ERR(journal_inode)) {
>  		ext4_msg(sb, KERN_ERR, "no journal found");
> -		return NULL;
> +		return ERR_CAST(journal_inode);
>  	}
>  	if (!journal_inode->i_nlink) {
>  		make_bad_inode(journal_inode);
>  		iput(journal_inode);
>  		ext4_msg(sb, KERN_ERR, "journal inode is deleted");
> -		return NULL;
> +		return ERR_PTR(-EFSCORRUPTED);
>  	}
>  	if (!S_ISREG(journal_inode->i_mode) || IS_ENCRYPTED(journal_inode)) {
>  		ext4_msg(sb, KERN_ERR, "invalid journal inode");
>  		iput(journal_inode);
> -		return NULL;
> +		return ERR_PTR(-EFSCORRUPTED);
>  	}
>  
>  	ext4_debug("Journal inode found at %p: %lld bytes\n",
> @@ -5793,21 +5793,21 @@ static int ext4_journal_bmap(journal_t *journal, sector_t *block)
>  	return 0;
>  }
>  
> -static journal_t *ext4_get_journal(struct super_block *sb,
> -				   unsigned int journal_inum)
> +static journal_t *ext4_open_inode_journal(struct super_block *sb,
> +					  unsigned int journal_inum)
>  {
>  	struct inode *journal_inode;
>  	journal_t *journal;
>  
>  	journal_inode = ext4_get_journal_inode(sb, journal_inum);
> -	if (!journal_inode)
> -		return NULL;
> +	if (IS_ERR(journal_inode))
> +		return ERR_CAST(journal_inode);
>  
>  	journal = jbd2_journal_init_inode(journal_inode);
>  	if (IS_ERR(journal)) {
>  		ext4_msg(sb, KERN_ERR, "Could not load journal inode");
>  		iput(journal_inode);
> -		return NULL;
> +		return ERR_CAST(journal);
>  	}
>  	journal->j_private = sb;
>  	journal->j_bmap = ext4_journal_bmap;
> @@ -5825,6 +5825,7 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb,
>  	ext4_fsblk_t sb_block;
>  	unsigned long offset;
>  	struct ext4_super_block *es;
> +	int errno;
>  
>  	bdev = blkdev_get_by_dev(j_dev, BLK_OPEN_READ | BLK_OPEN_WRITE, sb,
>  				 &ext4_holder_ops);
> @@ -5832,7 +5833,7 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb,
>  		ext4_msg(sb, KERN_ERR,
>  			 "failed to open journal device unknown-block(%u,%u) %ld",
>  			 MAJOR(j_dev), MINOR(j_dev), PTR_ERR(bdev));
> -		return NULL;
> +		return ERR_CAST(bdev);
>  	}
>  
>  	blocksize = sb->s_blocksize;
> @@ -5840,6 +5841,7 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb,
>  	if (blocksize < hblock) {
>  		ext4_msg(sb, KERN_ERR,
>  			"blocksize too small for journal device");
> +		errno = -EINVAL;
>  		goto out_bdev;
>  	}
>  
> @@ -5850,6 +5852,7 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb,
>  	if (!bh) {
>  		ext4_msg(sb, KERN_ERR, "couldn't read superblock of "
>  		       "external journal");
> +		errno = -EINVAL;
>  		goto out_bdev;
>  	}
>  
> @@ -5858,6 +5861,7 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb,
>  	    !(le32_to_cpu(es->s_feature_incompat) &
>  	      EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
>  		ext4_msg(sb, KERN_ERR, "external journal has bad superblock");
> +		errno = -EFSCORRUPTED;
>  		goto out_bh;
>  	}
>  
> @@ -5865,11 +5869,13 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb,
>  	     EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
>  	    es->s_checksum != ext4_superblock_csum(sb, es)) {
>  		ext4_msg(sb, KERN_ERR, "external journal has corrupt superblock");
> +		errno = -EFSCORRUPTED;
>  		goto out_bh;
>  	}
>  
>  	if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
>  		ext4_msg(sb, KERN_ERR, "journal UUID does not match");
> +		errno = -EFSCORRUPTED;
>  		goto out_bh;
>  	}
>  
> @@ -5882,31 +5888,34 @@ static struct block_device *ext4_get_journal_dev(struct super_block *sb,
>  	brelse(bh);
>  out_bdev:
>  	blkdev_put(bdev, sb);
> -	return NULL;
> +	return ERR_PTR(errno);
>  }
>  
> -static journal_t *ext4_get_dev_journal(struct super_block *sb,
> -				       dev_t j_dev)
> +static journal_t *ext4_open_dev_journal(struct super_block *sb,
> +					dev_t j_dev)
>  {
>  	journal_t *journal;
>  	ext4_fsblk_t j_start;
>  	ext4_fsblk_t j_len;
>  	struct block_device *journal_bdev;
> +	int errno = 0;
>  
>  	journal_bdev = ext4_get_journal_dev(sb, j_dev, &j_start, &j_len);
> -	if (!journal_bdev)
> -		return NULL;
> +	if (IS_ERR(journal_bdev))
> +		return ERR_CAST(journal_bdev);
>  
>  	journal = jbd2_journal_init_dev(journal_bdev, sb->s_bdev, j_start,
>  					j_len, sb->s_blocksize);
>  	if (IS_ERR(journal)) {
>  		ext4_msg(sb, KERN_ERR, "failed to create device journal");
> +		errno = PTR_ERR(journal);
>  		goto out_bdev;
>  	}
>  	if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
>  		ext4_msg(sb, KERN_ERR, "External journal has more than one "
>  					"user (unsupported) - %d",
>  			be32_to_cpu(journal->j_superblock->s_nr_users));
> +		errno = -EINVAL;
>  		goto out_journal;
>  	}
>  	journal->j_private = sb;
> @@ -5918,7 +5927,7 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
>  	jbd2_journal_destroy(journal);
>  out_bdev:
>  	blkdev_put(journal_bdev, sb);
> -	return NULL;
> +	return ERR_PTR(errno);
>  }
>  
>  static int ext4_load_journal(struct super_block *sb,
> @@ -5950,13 +5959,13 @@ static int ext4_load_journal(struct super_block *sb,
>  	}
>  
>  	if (journal_inum) {
> -		journal = ext4_get_journal(sb, journal_inum);
> -		if (!journal)
> -			return -EINVAL;
> +		journal = ext4_open_inode_journal(sb, journal_inum);
> +		if (IS_ERR(journal))
> +			return PTR_ERR(journal);
>  	} else {
> -		journal = ext4_get_dev_journal(sb, journal_dev);
> -		if (!journal)
> -			return -EINVAL;
> +		journal = ext4_open_dev_journal(sb, journal_dev);
> +		if (IS_ERR(journal))
> +			return PTR_ERR(journal);
>  	}
>  
>  	journal_dev_ro = bdev_read_only(journal->j_dev);
> -- 
> 2.39.2
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

      reply	other threads:[~2023-08-03 16:19 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-04 13:42 [PATCH 00/12] ext4,jbd2: cleanup journal load and initialization process Zhang Yi
2023-07-04 13:42 ` [PATCH 01/12] jbd2: move load_superblock() dependent functions Zhang Yi
2023-08-03 14:07   ` Jan Kara
2023-07-04 13:42 ` [PATCH 02/12] jbd2: move load_superblock() into journal_init_common() Zhang Yi
2023-08-03 14:13   ` Jan Kara
2023-07-04 13:42 ` [PATCH 03/12] jbd2: don't load superblock in jbd2_journal_check_used_features() Zhang Yi
2023-08-03 14:14   ` Jan Kara
2023-07-04 13:42 ` [PATCH 04/12] jbd2: checking valid features early in journal_get_superblock() Zhang Yi
2023-08-03 14:18   ` Jan Kara
2023-07-04 13:42 ` [PATCH 05/12] jbd2: open code jbd2_verify_csum_type() helper Zhang Yi
2023-08-03 14:19   ` Jan Kara
2023-07-04 13:42 ` [PATCH 06/12] jbd2: cleanup load_superblock() Zhang Yi
2023-08-03 14:28   ` Jan Kara
2023-07-04 13:42 ` [PATCH 07/12] jbd2: add fast_commit space check Zhang Yi
2023-08-03 14:38   ` Jan Kara
2023-08-07 10:53     ` Zhang Yi
2023-08-07 13:33       ` Jan Kara
2023-07-04 13:42 ` [PATCH 08/12] jbd2: cleanup journal_init_common() Zhang Yi
2023-08-03 15:48   ` Jan Kara
2023-07-04 13:42 ` [PATCH 09/12] jbd2: drop useless error tag in jbd2_journal_wipe() Zhang Yi
2023-08-03 15:49   ` Jan Kara
2023-07-04 13:42 ` [PATCH 10/12] jbd2: jbd2_journal_init_{dev,inode} return proper error return value Zhang Yi
2023-08-03 15:56   ` Jan Kara
2023-07-04 13:42 ` [PATCH 11/12] ext4: cleanup ext4_get_dev_journal() and ext4_get_journal() Zhang Yi
2023-08-03 16:14   ` Jan Kara
2023-08-07 11:36     ` Zhang Yi
2023-07-04 13:42 ` [PATCH 12/12] ext4: ext4_get_{dev}_journal return proper error value Zhang Yi
2023-08-03 16:19   ` Jan Kara [this message]

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=20230803161907.dsug5kqmxvn25kkf@quack3 \
    --to=jack@suse.cz \
    --cc=adilger.kernel@dilger.ca \
    --cc=chengzhihao1@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    --cc=yi.zhang@huaweicloud.com \
    --cc=yukuai3@huawei.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox