From 54cbfd8607248d6ac87239b1b25f468defd9d6f2 Mon Sep 17 00:00:00 2001 From: lihaoxiang Date: Wed, 8 Feb 2023 21:47:31 -0500 Subject: [PATCH] Upstream patches regress for debugfs, tune2fs and mmp. --- ...ated-output-problem-with-logdump-O-n.patch | 76 +++++++++++++++++++ ...turn-value-of-ext2fs_mmp_update2-in-.patch | 73 ++++++++++++++++++ ...-wrong-comparison-in-ext2fs_mmp_stop.patch | 43 +++++++++++ e2fsprogs.spec | 8 +- 4 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 0019-debugfs-fix-repeated-output-problem-with-logdump-O-n.patch create mode 100644 0020-tune2fs-check-return-value-of-ext2fs_mmp_update2-in-.patch create mode 100644 0021-mmp-fix-wrong-comparison-in-ext2fs_mmp_stop.patch diff --git a/0019-debugfs-fix-repeated-output-problem-with-logdump-O-n.patch b/0019-debugfs-fix-repeated-output-problem-with-logdump-O-n.patch new file mode 100644 index 0000000..0c06720 --- /dev/null +++ b/0019-debugfs-fix-repeated-output-problem-with-logdump-O-n.patch @@ -0,0 +1,76 @@ +From d37a9f1818fa04fc91a497b3541ed205804720af Mon Sep 17 00:00:00 2001 +From: "lihaoxiang (F)" +Date: Tue, 15 Nov 2022 16:29:55 +0800 +Subject: [PATCH] debugfs: fix repeated output problem with `logdump -O -n + ` + +Previously, patch 6e4cc3d5eeb2dfaa055e652b5390beaa6c3d05da introduces +the function of printing the specified number of logs. But there exists +a shortage when n is larger than the total number of logs, it dumped the +duplicated records circulately. + +For example, the disk sda only has three records, but using instruction logdump +-On5, it would output the result as follow: +---------------------------------------------------------------------- +Journal starts at block 1, transaction 6 +Found expected sequence 6, type 1 (descriptor block) at block 1 +Found expected sequence 6, type 2 (commit block) at block 4 +No magic number at block 5: end of journal. +Found sequence 2 (not 7) at block 7: end of journal. +Found expected sequence 2, type 2 (commit block) at block 7 +Found sequence 3 (not 8) at block 8: end of journal. +Found expected sequence 3, type 1 (descriptor block) at block 8 +Found sequence 3 (not 8) at block 15: end of journal. +Found expected sequence 3, type 2 (commit block) at block 15 +Found sequence 6 (not 9) at block 1: end of journal. <---------begin loop +Found expected sequence 6, type 1 (descriptor block) at block 1 +Found sequence 6 (not 9) at block 4: end of journal. +Found expected sequence 6, type 2 (commit block) at block 4 +Found sequence 2 (not 10) at block 7: end of journal. +Found expected sequence 2, type 2 (commit block) at block 7 +logdump: short read (read 0, expected 1024) while reading journal + +In this commit, we solve the problem above by exiting dumping if the +blocknr had already encountered, displayed the total number of logs +that the disk only possessed. + +Signed-off-by: lihaoxiang +Signed-off-by: Theodore Ts'o +--- + debugfs/logdump.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/debugfs/logdump.c b/debugfs/logdump.c +index 614414e..036b50b 100644 +--- a/debugfs/logdump.c ++++ b/debugfs/logdump.c +@@ -376,6 +376,7 @@ static void dump_journal(char *cmdname, FILE *out_file, + journal_header_t *header; + tid_t transaction; + unsigned int blocknr = 0; ++ unsigned int first_transaction_blocknr; + int fc_done; + __u64 total_len; + __u32 maxlen; +@@ -470,10 +471,18 @@ static void dump_journal(char *cmdname, FILE *out_file, + blocknr = 1; + } + ++ first_transaction_blocknr = blocknr; ++ + while (1) { + if (dump_old && (dump_counts != -1) && (cur_counts >= dump_counts)) + break; + ++ if ((blocknr == first_transaction_blocknr) && ++ (cur_counts != 0) && dump_old && (dump_counts != -1)) { ++ fprintf(out_file, "Dump all %lld journal records.\n", cur_counts); ++ break; ++ } ++ + retval = read_journal_block(cmdname, source, + ((ext2_loff_t) blocknr) * blocksize, + buf, blocksize); +-- +1.8.3.1 + diff --git a/0020-tune2fs-check-return-value-of-ext2fs_mmp_update2-in-.patch b/0020-tune2fs-check-return-value-of-ext2fs_mmp_update2-in-.patch new file mode 100644 index 0000000..e2a8ab4 --- /dev/null +++ b/0020-tune2fs-check-return-value-of-ext2fs_mmp_update2-in-.patch @@ -0,0 +1,73 @@ +From f7c9598655420102353ff87946f5bf77ebf465bc Mon Sep 17 00:00:00 2001 +From: "lihaoxiang (F)" +Date: Tue, 29 Nov 2022 14:58:12 +0800 +Subject: [PATCH] tune2fs: check return value of ext2fs_mmp_update2 in + rewrite_metadata_checksums + +Tune2fs hasn't consider about the result of executing ext2fs_mmp_update2 +when it try to rewrite_metadata_checksums. If the ext2fs_mmp_update2 +failed, multi-mount protection couldn't guard there has the only node +(i.e. this program) accessing this device in the meantime. + +We solve this problem to verify the return value of ext2fs_mmp_update2. +It terminate rewrite_metadata_checksums and exit immediately if the +wrong error code returned. + +Signed-off-by: lihaoxiang +Signed-off-by: Theodore Ts'o +--- + misc/tune2fs.c | 17 +++++++++++++---- + 1 file changed, 13 insertions(+), 4 deletions(-) + +diff --git a/misc/tune2fs.c b/misc/tune2fs.c +index b1e49b3..cb5f575 100644 +--- a/misc/tune2fs.c ++++ b/misc/tune2fs.c +@@ -930,7 +930,7 @@ static void rewrite_inodes(ext2_filsys fs, unsigned int flags) + ext2fs_free_mem(&ctx.ea_buf); + } + +-static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags) ++static errcode_t rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags) + { + errcode_t retval; + dgrp_t i; +@@ -945,7 +945,9 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags) + rewrite_inodes(fs, flags); + ext2fs_mark_ib_dirty(fs); + ext2fs_mark_bb_dirty(fs); +- ext2fs_mmp_update2(fs, 1); ++ retval = ext2fs_mmp_update2(fs, 1); ++ if (retval) ++ return retval; + fs->flags &= ~EXT2_FLAG_SUPER_ONLY; + fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS; + if (ext2fs_has_feature_metadata_csum(fs->super)) +@@ -953,6 +955,7 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags) + else + fs->super->s_checksum_type = 0; + ext2fs_mark_super_dirty(fs); ++ return 0; + } + + static void enable_uninit_bg(ext2_filsys fs) +@@ -3412,8 +3415,14 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n" + } + } + +- if (rewrite_checksums) +- rewrite_metadata_checksums(fs, rewrite_checksums); ++ if (rewrite_checksums) { ++ retval = rewrite_metadata_checksums(fs, rewrite_checksums); ++ if (retval != 0) { ++ printf("Failed to rewrite metadata checksums\n"); ++ rc = 1; ++ goto closefs; ++ } ++ } + + if (l_flag) + list_super(sb); +-- +1.8.3.1 + diff --git a/0021-mmp-fix-wrong-comparison-in-ext2fs_mmp_stop.patch b/0021-mmp-fix-wrong-comparison-in-ext2fs_mmp_stop.patch new file mode 100644 index 0000000..56979f6 --- /dev/null +++ b/0021-mmp-fix-wrong-comparison-in-ext2fs_mmp_stop.patch @@ -0,0 +1,43 @@ +From ffa6de1e3da4216a2ed6ec2890e16b22dc2ca40f Mon Sep 17 00:00:00 2001 +From: "lihaoxiang (F)" +Date: Tue, 29 Nov 2022 15:02:39 +0800 +Subject: [PATCH] mmp: fix wrong comparison in ext2fs_mmp_stop + +In our knowledge, ext2fs_mmp_stop use to process the rest of work +when mmp will finish. Critically, it must check if the mmp block is +not changed. But there exist an error in comparing the mmp and mmp_cmp. + +Look to ext2fs_mmp_read, the assignment of mmp_cmp retrieve from the +superblock of disk and it copy to mmp_buf if mmp_buf is not none +and not equal to mmp_cmp in the meanwhile. However, ext2fs_mmp_stop +pass the no NULL pointer fs->mmp_buf which has possed the mmp info to +ext2fs_mmp_read. Consequently, ext2fs_mmp_read override fs->mmp_buf +by fs->mmp_cmp so that loss the meaning of comparing themselves +after that and worse yet, couldn't judge whether the struct of mmp +has changed. + +In fact, we only need to modify the parameter to NULL pointer for +solving this problem. + +Signed-off-by: lihaoxiang +Signed-off-by: Theodore Ts'o +--- + lib/ext2fs/mmp.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c +index 7970aac..1428970 100644 +--- a/lib/ext2fs/mmp.c ++++ b/lib/ext2fs/mmp.c +@@ -407,7 +407,7 @@ errcode_t ext2fs_mmp_stop(ext2_filsys fs) + (fs->mmp_buf == NULL) || (fs->mmp_cmp == NULL)) + goto mmp_error; + +- retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); ++ retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, NULL); + if (retval) + goto mmp_error; + +-- +1.8.3.1 + diff --git a/e2fsprogs.spec b/e2fsprogs.spec index 6dd488c..d2fed8d 100644 --- a/e2fsprogs.spec +++ b/e2fsprogs.spec @@ -1,6 +1,6 @@ Name: e2fsprogs Version: 1.46.5 -Release: 3 +Release: 4 Summary: Second extended file system management tools License: GPLv2+ and LGPLv2 and MIT URL: http://e2fsprogs.sourceforge.net/ @@ -25,6 +25,9 @@ Patch15: 0015-tune2fs-tune2fs_main-should-return-rc-when-some-erro.patch Patch16: 0016-tune2fs-exit-directly-when-fs-freed-in-ext2fs_run_ext3_journal.patch Patch17: 0017-unix_io.c-fix-deadlock-problem-in-unix_write_blk64.patch Patch18: 0018-misc-fsck.c-Processes-may-kill-other-processes.patch +Patch19: 0019-debugfs-fix-repeated-output-problem-with-logdump-O-n.patch +Patch20: 0020-tune2fs-check-return-value-of-ext2fs_mmp_update2-in-.patch +Patch21: 0021-mmp-fix-wrong-comparison-in-ext2fs_mmp_stop.patch BuildRequires: gcc pkgconfig texinfo @@ -166,6 +169,9 @@ exit 0 %{_mandir}/man8/* %changelog +* Thu Feb 9 2023 lihaoxiang - 1.46.5-4 +- Upstream patches regress for debugfs, tune2fs and mmp. + * Mon Jan 30 2023 zhanchengbin - 1.46.5-3 - misc/fsck.c: Processes may kill other processes. -- Gitee