* [PATCH 0/2] e2fsprogs: avoid error information loss during journal replay
@ 2023-02-17 10:09 Baokun Li
2023-02-17 10:09 ` [PATCH 1/2] e2fsck: save EXT2_ERROR_FS flag " Baokun Li
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Baokun Li @ 2023-02-17 10:09 UTC (permalink / raw)
To: linux-ext4
Cc: tytso, adilger.kernel, jack, yi.zhang, yangerkun, yukuai3,
libaokun1
Baokun Li (2):
e2fsck: save EXT2_ERROR_FS flag during journal replay
tune2fs/fuse2fs/debugfs: save error information during journal replay
debugfs/journal.c | 17 ++++++++++++++++-
e2fsck/journal.c | 3 +++
2 files changed, 19 insertions(+), 1 deletion(-)
--
2.31.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] e2fsck: save EXT2_ERROR_FS flag during journal replay
2023-02-17 10:09 [PATCH 0/2] e2fsprogs: avoid error information loss during journal replay Baokun Li
@ 2023-02-17 10:09 ` Baokun Li
2023-02-17 11:10 ` Jan Kara
2023-06-06 9:10 ` zhanchengbin
2023-02-17 10:09 ` [PATCH 2/2] tune2fs/fuse2fs/debugfs: save error information " Baokun Li
2023-12-07 16:05 ` [PATCH 0/2] e2fsprogs: avoid error information loss " Theodore Ts'o
2 siblings, 2 replies; 8+ messages in thread
From: Baokun Li @ 2023-02-17 10:09 UTC (permalink / raw)
To: linux-ext4
Cc: tytso, adilger.kernel, jack, yi.zhang, yangerkun, yukuai3,
libaokun1
When repairing a file system with s_errno missing from the journal
superblock but the file system superblock contains the ERROR_FS flag,
the ERROR_FS flag on the file system image is overwritten after the
journal replay, followed by a reload of the file system data from disk
and the ERROR_FS flag in memory is overwritten. Also s_errno is not set
and the ERROR_FS flag is not reset. Therefore, when checked later, no
forced check is performed, which makes it possible to have some errors
hidden in the disk image, which may make it read-only when using the
file system. So we save the ERROR_FS flag to the superblock after the
journal replay, instead of just relying on the jsb->s_errno to do this.
Signed-off-by: Baokun Li <libaokun1@huawei.com>
---
e2fsck/journal.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/e2fsck/journal.c b/e2fsck/journal.c
index c7868d89..0144aa45 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -1683,6 +1683,7 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx)
errcode_t retval, recover_retval;
io_stats stats = 0;
unsigned long long kbytes_written = 0;
+ __u16 s_error_state;
printf(_("%s: recovering journal\n"), ctx->device_name);
if (ctx->options & E2F_OPT_READONLY) {
@@ -1705,6 +1706,7 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx)
ctx->fs->io->manager->get_stats(ctx->fs->io, &stats);
if (stats && stats->bytes_written)
kbytes_written = stats->bytes_written >> 10;
+ s_error_state = ctx->fs->super->s_state & EXT2_ERROR_FS;
ext2fs_mmp_stop(ctx->fs);
ext2fs_free(ctx->fs);
@@ -1721,6 +1723,7 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx)
ctx->fs->now = ctx->now;
ctx->fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
ctx->fs->super->s_kbytes_written += kbytes_written;
+ ctx->fs->super->s_state |= s_error_state;
/* Set the superblock flags */
e2fsck_clear_recover(ctx, recover_retval != 0);
--
2.31.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] tune2fs/fuse2fs/debugfs: save error information during journal replay
2023-02-17 10:09 [PATCH 0/2] e2fsprogs: avoid error information loss during journal replay Baokun Li
2023-02-17 10:09 ` [PATCH 1/2] e2fsck: save EXT2_ERROR_FS flag " Baokun Li
@ 2023-02-17 10:09 ` Baokun Li
2023-02-17 11:11 ` Jan Kara
2023-06-06 9:11 ` zhanchengbin
2023-12-07 16:05 ` [PATCH 0/2] e2fsprogs: avoid error information loss " Theodore Ts'o
2 siblings, 2 replies; 8+ messages in thread
From: Baokun Li @ 2023-02-17 10:09 UTC (permalink / raw)
To: linux-ext4
Cc: tytso, adilger.kernel, jack, yi.zhang, yangerkun, yukuai3,
libaokun1
Saving error information during journal replay, as in the kernel,
prevents information loss from making problems difficult to locate.
We save these error information until someone uses e2fsck to check
for and fix possible errors.
Signed-off-by: Baokun Li <libaokun1@huawei.com>
---
debugfs/journal.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/debugfs/journal.c b/debugfs/journal.c
index 5bac0d3b..79e3fff8 100644
--- a/debugfs/journal.c
+++ b/debugfs/journal.c
@@ -789,6 +789,8 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
char *fsname;
int fsflags;
int fsblocksize;
+ char *save;
+ __u16 s_error_state;
if (!(fs->flags & EXT2_FLAG_RW))
return EXT2_ET_FILE_RO;
@@ -808,6 +810,12 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
if (stats && stats->bytes_written)
kbytes_written = stats->bytes_written >> 10;
+ save = malloc(EXT4_S_ERR_LEN);
+ if (save)
+ memcpy(save, ((char *) fs->super) + EXT4_S_ERR_START,
+ EXT4_S_ERR_LEN);
+ s_error_state = fs->super->s_state & EXT2_ERROR_FS;
+
ext2fs_mmp_stop(fs);
fsname = fs->device_name;
fs->device_name = NULL;
@@ -818,11 +826,15 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
retval = ext2fs_open(fsname, fsflags, 0, fsblocksize, io_ptr, fsp);
ext2fs_free_mem(&fsname);
if (retval)
- return retval;
+ goto outfree;
fs = *fsp;
fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
fs->super->s_kbytes_written += kbytes_written;
+ fs->super->s_state |= s_error_state;
+ if (save)
+ memcpy(((char *) fs->super) + EXT4_S_ERR_START, save,
+ EXT4_S_ERR_LEN);
/* Set the superblock flags */
ext2fs_clear_recover(fs, recover_retval != 0);
@@ -832,6 +844,9 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
* the EXT2_ERROR_FS flag in the fs superblock if needed.
*/
retval = ext2fs_check_ext3_journal(fs);
+
+outfree:
+ free(save);
return retval ? retval : recover_retval;
}
--
2.31.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] e2fsck: save EXT2_ERROR_FS flag during journal replay
2023-02-17 10:09 ` [PATCH 1/2] e2fsck: save EXT2_ERROR_FS flag " Baokun Li
@ 2023-02-17 11:10 ` Jan Kara
2023-06-06 9:10 ` zhanchengbin
1 sibling, 0 replies; 8+ messages in thread
From: Jan Kara @ 2023-02-17 11:10 UTC (permalink / raw)
To: Baokun Li
Cc: linux-ext4, tytso, adilger.kernel, jack, yi.zhang, yangerkun,
yukuai3
On Fri 17-02-23 18:09:21, Baokun Li wrote:
> When repairing a file system with s_errno missing from the journal
> superblock but the file system superblock contains the ERROR_FS flag,
> the ERROR_FS flag on the file system image is overwritten after the
> journal replay, followed by a reload of the file system data from disk
> and the ERROR_FS flag in memory is overwritten. Also s_errno is not set
> and the ERROR_FS flag is not reset. Therefore, when checked later, no
> forced check is performed, which makes it possible to have some errors
> hidden in the disk image, which may make it read-only when using the
> file system. So we save the ERROR_FS flag to the superblock after the
> journal replay, instead of just relying on the jsb->s_errno to do this.
>
> Signed-off-by: Baokun Li <libaokun1@huawei.com>
Looks good to me. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> e2fsck/journal.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/e2fsck/journal.c b/e2fsck/journal.c
> index c7868d89..0144aa45 100644
> --- a/e2fsck/journal.c
> +++ b/e2fsck/journal.c
> @@ -1683,6 +1683,7 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx)
> errcode_t retval, recover_retval;
> io_stats stats = 0;
> unsigned long long kbytes_written = 0;
> + __u16 s_error_state;
>
> printf(_("%s: recovering journal\n"), ctx->device_name);
> if (ctx->options & E2F_OPT_READONLY) {
> @@ -1705,6 +1706,7 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx)
> ctx->fs->io->manager->get_stats(ctx->fs->io, &stats);
> if (stats && stats->bytes_written)
> kbytes_written = stats->bytes_written >> 10;
> + s_error_state = ctx->fs->super->s_state & EXT2_ERROR_FS;
>
> ext2fs_mmp_stop(ctx->fs);
> ext2fs_free(ctx->fs);
> @@ -1721,6 +1723,7 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx)
> ctx->fs->now = ctx->now;
> ctx->fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
> ctx->fs->super->s_kbytes_written += kbytes_written;
> + ctx->fs->super->s_state |= s_error_state;
>
> /* Set the superblock flags */
> e2fsck_clear_recover(ctx, recover_retval != 0);
> --
> 2.31.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] tune2fs/fuse2fs/debugfs: save error information during journal replay
2023-02-17 10:09 ` [PATCH 2/2] tune2fs/fuse2fs/debugfs: save error information " Baokun Li
@ 2023-02-17 11:11 ` Jan Kara
2023-06-06 9:11 ` zhanchengbin
1 sibling, 0 replies; 8+ messages in thread
From: Jan Kara @ 2023-02-17 11:11 UTC (permalink / raw)
To: Baokun Li
Cc: linux-ext4, tytso, adilger.kernel, jack, yi.zhang, yangerkun,
yukuai3
On Fri 17-02-23 18:09:22, Baokun Li wrote:
> Saving error information during journal replay, as in the kernel,
> prevents information loss from making problems difficult to locate.
> We save these error information until someone uses e2fsck to check
> for and fix possible errors.
>
> Signed-off-by: Baokun Li <libaokun1@huawei.com>
Looks good to me. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> debugfs/journal.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/debugfs/journal.c b/debugfs/journal.c
> index 5bac0d3b..79e3fff8 100644
> --- a/debugfs/journal.c
> +++ b/debugfs/journal.c
> @@ -789,6 +789,8 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
> char *fsname;
> int fsflags;
> int fsblocksize;
> + char *save;
> + __u16 s_error_state;
>
> if (!(fs->flags & EXT2_FLAG_RW))
> return EXT2_ET_FILE_RO;
> @@ -808,6 +810,12 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
> if (stats && stats->bytes_written)
> kbytes_written = stats->bytes_written >> 10;
>
> + save = malloc(EXT4_S_ERR_LEN);
> + if (save)
> + memcpy(save, ((char *) fs->super) + EXT4_S_ERR_START,
> + EXT4_S_ERR_LEN);
> + s_error_state = fs->super->s_state & EXT2_ERROR_FS;
> +
> ext2fs_mmp_stop(fs);
> fsname = fs->device_name;
> fs->device_name = NULL;
> @@ -818,11 +826,15 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
> retval = ext2fs_open(fsname, fsflags, 0, fsblocksize, io_ptr, fsp);
> ext2fs_free_mem(&fsname);
> if (retval)
> - return retval;
> + goto outfree;
>
> fs = *fsp;
> fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
> fs->super->s_kbytes_written += kbytes_written;
> + fs->super->s_state |= s_error_state;
> + if (save)
> + memcpy(((char *) fs->super) + EXT4_S_ERR_START, save,
> + EXT4_S_ERR_LEN);
>
> /* Set the superblock flags */
> ext2fs_clear_recover(fs, recover_retval != 0);
> @@ -832,6 +844,9 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
> * the EXT2_ERROR_FS flag in the fs superblock if needed.
> */
> retval = ext2fs_check_ext3_journal(fs);
> +
> +outfree:
> + free(save);
> return retval ? retval : recover_retval;
> }
>
> --
> 2.31.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] e2fsck: save EXT2_ERROR_FS flag during journal replay
2023-02-17 10:09 ` [PATCH 1/2] e2fsck: save EXT2_ERROR_FS flag " Baokun Li
2023-02-17 11:10 ` Jan Kara
@ 2023-06-06 9:10 ` zhanchengbin
1 sibling, 0 replies; 8+ messages in thread
From: zhanchengbin @ 2023-06-06 9:10 UTC (permalink / raw)
To: Baokun Li, linux-ext4
Cc: tytso, adilger.kernel, jack, yi.zhang, yangerkun, yukuai3
On 2023/2/17 18:09, Baokun Li wrote:
> When repairing a file system with s_errno missing from the journal
> superblock but the file system superblock contains the ERROR_FS flag,
> the ERROR_FS flag on the file system image is overwritten after the
> journal replay, followed by a reload of the file system data from disk
> and the ERROR_FS flag in memory is overwritten. Also s_errno is not set
> and the ERROR_FS flag is not reset. Therefore, when checked later, no
> forced check is performed, which makes it possible to have some errors
> hidden in the disk image, which may make it read-only when using the
> file system. So we save the ERROR_FS flag to the superblock after the
> journal replay, instead of just relying on the jsb->s_errno to do this.
>
> Signed-off-by: Baokun Li <libaokun1@huawei.com>
Looks good to me. Feel free to add:
Reviewed-by: zhanchengbin <zhanchengbin1@huawei.com>
- bin.
> ---
> e2fsck/journal.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/e2fsck/journal.c b/e2fsck/journal.c
> index c7868d89..0144aa45 100644
> --- a/e2fsck/journal.c
> +++ b/e2fsck/journal.c
> @@ -1683,6 +1683,7 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx)
> errcode_t retval, recover_retval;
> io_stats stats = 0;
> unsigned long long kbytes_written = 0;
> + __u16 s_error_state;
>
> printf(_("%s: recovering journal\n"), ctx->device_name);
> if (ctx->options & E2F_OPT_READONLY) {
> @@ -1705,6 +1706,7 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx)
> ctx->fs->io->manager->get_stats(ctx->fs->io, &stats);
> if (stats && stats->bytes_written)
> kbytes_written = stats->bytes_written >> 10;
> + s_error_state = ctx->fs->super->s_state & EXT2_ERROR_FS;
>
> ext2fs_mmp_stop(ctx->fs);
> ext2fs_free(ctx->fs);
> @@ -1721,6 +1723,7 @@ errcode_t e2fsck_run_ext3_journal(e2fsck_t ctx)
> ctx->fs->now = ctx->now;
> ctx->fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
> ctx->fs->super->s_kbytes_written += kbytes_written;
> + ctx->fs->super->s_state |= s_error_state;
>
> /* Set the superblock flags */
> e2fsck_clear_recover(ctx, recover_retval != 0);
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] tune2fs/fuse2fs/debugfs: save error information during journal replay
2023-02-17 10:09 ` [PATCH 2/2] tune2fs/fuse2fs/debugfs: save error information " Baokun Li
2023-02-17 11:11 ` Jan Kara
@ 2023-06-06 9:11 ` zhanchengbin
1 sibling, 0 replies; 8+ messages in thread
From: zhanchengbin @ 2023-06-06 9:11 UTC (permalink / raw)
To: Baokun Li, linux-ext4
Cc: tytso, adilger.kernel, jack, yi.zhang, yangerkun, yukuai3
On 2023/2/17 18:09, Baokun Li wrote:
> Saving error information during journal replay, as in the kernel,
> prevents information loss from making problems difficult to locate.
> We save these error information until someone uses e2fsck to check
> for and fix possible errors.
>
> Signed-off-by: Baokun Li <libaokun1@huawei.com>
Looks good to me. Feel free to add:
Reviewed-by: zhanchengbin <zhanchengbin1@huawei.com>
- bin.
> ---
> debugfs/journal.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/debugfs/journal.c b/debugfs/journal.c
> index 5bac0d3b..79e3fff8 100644
> --- a/debugfs/journal.c
> +++ b/debugfs/journal.c
> @@ -789,6 +789,8 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
> char *fsname;
> int fsflags;
> int fsblocksize;
> + char *save;
> + __u16 s_error_state;
>
> if (!(fs->flags & EXT2_FLAG_RW))
> return EXT2_ET_FILE_RO;
> @@ -808,6 +810,12 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
> if (stats && stats->bytes_written)
> kbytes_written = stats->bytes_written >> 10;
>
> + save = malloc(EXT4_S_ERR_LEN);
> + if (save)
> + memcpy(save, ((char *) fs->super) + EXT4_S_ERR_START,
> + EXT4_S_ERR_LEN);
> + s_error_state = fs->super->s_state & EXT2_ERROR_FS;
> +
> ext2fs_mmp_stop(fs);
> fsname = fs->device_name;
> fs->device_name = NULL;
> @@ -818,11 +826,15 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
> retval = ext2fs_open(fsname, fsflags, 0, fsblocksize, io_ptr, fsp);
> ext2fs_free_mem(&fsname);
> if (retval)
> - return retval;
> + goto outfree;
>
> fs = *fsp;
> fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
> fs->super->s_kbytes_written += kbytes_written;
> + fs->super->s_state |= s_error_state;
> + if (save)
> + memcpy(((char *) fs->super) + EXT4_S_ERR_START, save,
> + EXT4_S_ERR_LEN);
>
> /* Set the superblock flags */
> ext2fs_clear_recover(fs, recover_retval != 0);
> @@ -832,6 +844,9 @@ errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
> * the EXT2_ERROR_FS flag in the fs superblock if needed.
> */
> retval = ext2fs_check_ext3_journal(fs);
> +
> +outfree:
> + free(save);
> return retval ? retval : recover_retval;
> }
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] e2fsprogs: avoid error information loss during journal replay
2023-02-17 10:09 [PATCH 0/2] e2fsprogs: avoid error information loss during journal replay Baokun Li
2023-02-17 10:09 ` [PATCH 1/2] e2fsck: save EXT2_ERROR_FS flag " Baokun Li
2023-02-17 10:09 ` [PATCH 2/2] tune2fs/fuse2fs/debugfs: save error information " Baokun Li
@ 2023-12-07 16:05 ` Theodore Ts'o
2 siblings, 0 replies; 8+ messages in thread
From: Theodore Ts'o @ 2023-12-07 16:05 UTC (permalink / raw)
To: linux-ext4, Baokun Li
Cc: Theodore Ts'o, adilger.kernel, jack, yi.zhang, yangerkun,
yukuai3
On Fri, 17 Feb 2023 18:09:20 +0800, Baokun Li wrote:
> Baokun Li (2):
> e2fsck: save EXT2_ERROR_FS flag during journal replay
> tune2fs/fuse2fs/debugfs: save error information during journal replay
>
> debugfs/journal.c | 17 ++++++++++++++++-
> e2fsck/journal.c | 3 +++
> 2 files changed, 19 insertions(+), 1 deletion(-)
>
> [...]
Applied, thanks!
[1/2] e2fsck: save EXT2_ERROR_FS flag during journal replay
commit: 6ab579ee3c6c8c2d76aebcc9e8430a797c9963ff
[2/2] tune2fs/fuse2fs/debugfs: save error information during journal replay
commit: d5296ff0c665c1f957252ee18f824ad666a34b78
Best regards,
--
Theodore Ts'o <tytso@mit.edu>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-12-07 16:06 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-17 10:09 [PATCH 0/2] e2fsprogs: avoid error information loss during journal replay Baokun Li
2023-02-17 10:09 ` [PATCH 1/2] e2fsck: save EXT2_ERROR_FS flag " Baokun Li
2023-02-17 11:10 ` Jan Kara
2023-06-06 9:10 ` zhanchengbin
2023-02-17 10:09 ` [PATCH 2/2] tune2fs/fuse2fs/debugfs: save error information " Baokun Li
2023-02-17 11:11 ` Jan Kara
2023-06-06 9:11 ` zhanchengbin
2023-12-07 16:05 ` [PATCH 0/2] e2fsprogs: avoid error information loss " Theodore Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).