All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@dilger.ca>
To: Jan Kara <jack@suse.cz>
Cc: Ted Tso <tytso@mit.edu>, linux-ext4@vger.kernel.org
Subject: Re: [PATCH 06/12] ext4: Simplify ext4 error translation
Date: Sun, 29 Nov 2020 14:57:26 -0700	[thread overview]
Message-ID: <CA656726-A5EA-4D72-9C40-95933085354A@dilger.ca> (raw)
In-Reply-To: <20201127113405.26867-7-jack@suse.cz>

[-- Attachment #1: Type: text/plain, Size: 4301 bytes --]

On Nov 27, 2020, at 4:33 AM, Jan Kara <jack@suse.cz> wrote:
> 
> We convert errno's to ext4 on-disk format error codes in
> save_error_info(). Add a function and a bit of macro magic to make this
> simpler.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>

In hindsight, it would have been better (IMHO) if the EXT4_ERR_* values mapped
to the standard x86_64 errors in errno.h, since that is what most admins/users
are familiar with (e.g. 5 = EIO, 12 = ENOMEM, 28 = ENOSPC, 30 = EROFS).  That
would avoid the need to look up the EXT4_ERR_* values, since it doesn't look
like dumpe2fs even handles these fields yet.

I guess I never noticed the original patch when it was submitted, so water under
the bridge, I guess...

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

> ---
> fs/ext4/super.c | 95 ++++++++++++++++++++++++---------------------------------
> 1 file changed, 40 insertions(+), 55 deletions(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 7948c07d0a90..8add06d08495 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -551,76 +551,61 @@ static bool system_going_down(void)
> 		|| system_state == SYSTEM_RESTART;
> }
> 
> +struct ext4_err_translation {
> +	int code;
> +	int errno;
> +};
> +
> +#define EXT4_ERR_TRANSLATE(err) { .code = EXT4_ERR_##err, .errno = err }
> +
> +static struct ext4_err_translation err_translation[] = {
> +	EXT4_ERR_TRANSLATE(EIO),
> +	EXT4_ERR_TRANSLATE(ENOMEM),
> +	EXT4_ERR_TRANSLATE(EFSBADCRC),
> +	EXT4_ERR_TRANSLATE(EFSCORRUPTED),
> +	EXT4_ERR_TRANSLATE(ENOSPC),
> +	EXT4_ERR_TRANSLATE(ENOKEY),
> +	EXT4_ERR_TRANSLATE(EROFS),
> +	EXT4_ERR_TRANSLATE(EFBIG),
> +	EXT4_ERR_TRANSLATE(EEXIST),
> +	EXT4_ERR_TRANSLATE(ERANGE),
> +	EXT4_ERR_TRANSLATE(EOVERFLOW),
> +	EXT4_ERR_TRANSLATE(EBUSY),
> +	EXT4_ERR_TRANSLATE(ENOTDIR),
> +	EXT4_ERR_TRANSLATE(ENOTEMPTY),
> +	EXT4_ERR_TRANSLATE(ESHUTDOWN),
> +	EXT4_ERR_TRANSLATE(EFAULT),
> +};
> +
> +static int ext4_errno_to_code(int errno)
> +{
> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(err_translation); i++)
> +		if (err_translation[i].errno == errno)
> +			return err_translation[i].code;
> +	return EXT4_ERR_UNKNOWN;
> +}
> +
> static void __save_error_info(struct super_block *sb, int error,
> 			      __u32 ino, __u64 block,
> 			      const char *func, unsigned int line)
> {
> 	struct ext4_super_block *es = EXT4_SB(sb)->s_es;
> -	int err;
> 
> 	EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
> 	if (bdev_read_only(sb->s_bdev))
> 		return;
> +	/* We default to EFSCORRUPTED error... */
> +	if (error == 0)
> +		error = EFSCORRUPTED;
> 	es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
> 	ext4_update_tstamp(es, s_last_error_time);
> 	strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
> 	es->s_last_error_line = cpu_to_le32(line);
> 	es->s_last_error_ino = cpu_to_le32(ino);
> 	es->s_last_error_block = cpu_to_le64(block);
> -	switch (error) {
> -	case EIO:
> -		err = EXT4_ERR_EIO;
> -		break;
> -	case ENOMEM:
> -		err = EXT4_ERR_ENOMEM;
> -		break;
> -	case EFSBADCRC:
> -		err = EXT4_ERR_EFSBADCRC;
> -		break;
> -	case 0:
> -	case EFSCORRUPTED:
> -		err = EXT4_ERR_EFSCORRUPTED;
> -		break;
> -	case ENOSPC:
> -		err = EXT4_ERR_ENOSPC;
> -		break;
> -	case ENOKEY:
> -		err = EXT4_ERR_ENOKEY;
> -		break;
> -	case EROFS:
> -		err = EXT4_ERR_EROFS;
> -		break;
> -	case EFBIG:
> -		err = EXT4_ERR_EFBIG;
> -		break;
> -	case EEXIST:
> -		err = EXT4_ERR_EEXIST;
> -		break;
> -	case ERANGE:
> -		err = EXT4_ERR_ERANGE;
> -		break;
> -	case EOVERFLOW:
> -		err = EXT4_ERR_EOVERFLOW;
> -		break;
> -	case EBUSY:
> -		err = EXT4_ERR_EBUSY;
> -		break;
> -	case ENOTDIR:
> -		err = EXT4_ERR_ENOTDIR;
> -		break;
> -	case ENOTEMPTY:
> -		err = EXT4_ERR_ENOTEMPTY;
> -		break;
> -	case ESHUTDOWN:
> -		err = EXT4_ERR_ESHUTDOWN;
> -		break;
> -	case EFAULT:
> -		err = EXT4_ERR_EFAULT;
> -		break;
> -	default:
> -		err = EXT4_ERR_UNKNOWN;
> -	}
> -	es->s_last_error_errcode = err;
> +	es->s_last_error_errcode = ext4_errno_to_code(error);
> 	if (!es->s_first_error_time) {
> 		es->s_first_error_time = es->s_last_error_time;
> 		es->s_first_error_time_hi = es->s_last_error_time_hi;
> --
> 2.16.4
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

  reply	other threads:[~2020-11-29 21:58 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27 11:33 [PATCH 00/12] ext4: Various fixes of ext4 handling of fs errors Jan Kara
2020-11-27 11:33 ` [PATCH 01/12] ext4: Don't remount read-only with errors=continue on reboot Jan Kara
2020-11-29 21:33   ` Andreas Dilger
2020-12-16  4:59     ` Theodore Y. Ts'o
2020-11-27 11:33 ` [PATCH 02/12] ext4: Remove redundant sb checksum recomputation Jan Kara
2020-11-29 22:11   ` Andreas Dilger
2020-11-30 10:59     ` Jan Kara
2020-12-16  5:01   ` Theodore Y. Ts'o
2020-11-27 11:33 ` [PATCH 03/12] ext4: Standardize error message in ext4_protect_reserved_inode() Jan Kara
2020-11-29 21:39   ` Andreas Dilger
2020-12-16  5:04   ` Theodore Y. Ts'o
2020-11-27 11:33 ` [PATCH 04/12] ext4: Make ext4_abort() use __ext4_error() Jan Kara
2020-11-29 22:12   ` Andreas Dilger
2020-12-16  5:07   ` Theodore Y. Ts'o
2020-11-27 11:33 ` [PATCH 05/12] ext4: Move functions in super.c Jan Kara
2020-11-29 22:13   ` Andreas Dilger
2020-12-16  5:09   ` Theodore Y. Ts'o
2020-11-27 11:33 ` [PATCH 06/12] ext4: Simplify ext4 error translation Jan Kara
2020-11-29 21:57   ` Andreas Dilger [this message]
2020-12-16  5:11   ` Theodore Y. Ts'o
2020-11-27 11:34 ` [PATCH 07/12] ext4: Defer saving error info from atomic context Jan Kara
2020-12-16  5:31   ` Theodore Y. Ts'o
2020-12-16  5:40     ` Theodore Y. Ts'o
2020-12-16  9:56       ` Jan Kara
2020-11-27 11:34 ` [PATCH 08/12] ext4: Combine ext4_handle_error() and save_error_info() Jan Kara
2020-12-14 19:23   ` harshad shirwadkar
2020-12-16 10:11     ` Jan Kara
2020-12-16 10:24       ` Jan Kara
2020-11-27 11:34 ` [PATCH 09/12] ext4: Drop sync argument of ext4_commit_super() Jan Kara
2020-12-14 19:25   ` harshad shirwadkar
2020-11-27 11:34 ` [PATCH 10/12] ext4: Protect superblock modifications with a buffer lock Jan Kara
2020-11-27 11:34 ` [PATCH 11/12] ext4: Save error info to sb through journal if available Jan Kara
2020-11-27 11:34 ` [PATCH 12/12] ext4: Use sbi instead of EXT4_SB(sb) in ext4_update_super() Jan Kara
2020-12-14 19:07 ` [PATCH 00/12] ext4: Various fixes of ext4 handling of fs errors harshad shirwadkar

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=CA656726-A5EA-4D72-9C40-95933085354A@dilger.ca \
    --to=adilger@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    --subject='Re: [PATCH 06/12] ext4: Simplify ext4 error translation' \
    /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

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.