Skip to contentSkip to conversation

e2fsprogs: Fix wrong error code after optimization

PATCH In review Daniel Schultz 2 participants 6 messages Mar 20, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 e2fsprogs: Fix wrong error code after optimization

fsck.ext will return an error code of 1 if a file systems was checked and successfully repaired. Even when an optimization was performed it will return this error code.

This patch will change the error code to 0 if only optimizations had changed the file systems.

The reason for this patch is a question I asked at the ext4 ML:
http://www.spinics.net/lists/linux-ext4/msg55700.html

Backport from git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git

    Based on commit bf9f3b6d5b10d19218b4ed904c12b22e36ec57dd
---
 ...-with-exit-status-0-if-no-errors-were-fix.patch | 255 +++++++++++++++++++++
 .../recipes-devtools/e2fsprogs/e2fsprogs_1.43.4.bb |   1 +
 2 files changed, 256 insertions(+)
 create mode 100644 meta/recipes-devtools/e2fsprogs/e2fsprogs/0001-e2fsck-exit-with-exit-status-0-if-no-errors-were-fix.patch
meta/recipes-devtools/e2fsprogs/e2fsprogs/0001-e2fsck-exit-with-exit-status-0-if-no-errors-were-fix.patch new file +255 -0
new file mode 100644
index 0000000..1d17520
@@ -0,0 +1,255 @@
+From bf9f3b6d5b10d19218b4ed904c12b22e36ec57dd Mon Sep 17 00:00:00 2001
+From: Theodore Ts'o <[email protected]>
+Date: Thu, 16 Feb 2017 22:02:35 -0500
+Subject: [PATCH] e2fsck: exit with exit status 0 if no errors were fixed
+
+Previously, e2fsck would exit with a status code of 1 even though the
+only changes that it made to the file system were various
+optimziations and not fixing file system corruption.  Since the man
+page states that an exit status of 1 means "file system errors
+corrupted", fix e2fsck to return an exit status of 0.
+
+Upstream-Status: Backport
+
+Signed-off-by: Theodore Ts'o <[email protected]>
+Signed-off-by: Daniel Schultz <[email protected]>
+---
+ e2fsck/e2fsck.conf.5.in                     |  7 +++++++
+ e2fsck/journal.c                            |  1 +
+ e2fsck/problem.c                            |  8 +++++---
+ e2fsck/problemP.h                           |  1 +
+ e2fsck/unix.c                               | 20 ++++++++++++++++----
+ tests/f_collapse_extent_tree/expect.1       |  2 +-
+ tests/f_compress_extent_tree_level/expect.1 |  2 +-
+ tests/f_convert_bmap/expect.1               |  2 +-
+ tests/f_convert_bmap_and_extent/expect.1    |  2 +-
+ tests/f_extent_htree/expect.1               |  2 +-
+ tests/f_jnl_errno/expect.1                  |  2 +-
+ tests/f_journal/expect.1                    |  2 +-
+ tests/f_orphan/expect.1                     |  2 +-
+ tests/f_orphan_extents_inode/expect.1       |  2 +-
+ tests/f_rehash_dir/expect.1                 |  2 +-
+ tests/f_unsorted_EAs/expect.1               |  2 +-
+ 16 files changed, 41 insertions(+), 18 deletions(-)
+
+diff --git a/e2fsck/e2fsck.conf.5.in b/e2fsck/e2fsck.conf.5.in
+index 1848bdb..0bfc76a 100644
+--- a/e2fsck/e2fsck.conf.5.in
++++ b/e2fsck/e2fsck.conf.5.in
+@@ -303,6 +303,13 @@ of 'should this problem be fixed?'.  The
+ option even overrides the
+ .B -y
+ option given on the command-line (just for the specific problem, of course).
++.TP
++.I not_a_fix
++This boolean option, it set to true, marks the problem as
++one where if the user gives permission to make the requested change,
++it does not mean that the file system had a problem which has since
++been fixed.  This is used for requests to optimize the file system's
++data structure, such as pruning an extent tree.
+ @[email protected] THE [scratch_files] STANZA
+ @TDB_MAN_COMMENT@The following relations are defined in the
+ @[email protected] [scratch_files]
+diff --git a/e2fsck/journal.c b/e2fsck/journal.c
+index 46fe7b4..c4f58f1 100644
+--- a/e2fsck/journal.c
++++ b/e2fsck/journal.c
+@@ -572,6 +572,7 @@ static void clear_v2_journal_fields(journal_t *journal)
+ 	if (!fix_problem(ctx, PR_0_CLEAR_V2_JOURNAL, &pctx))
+ 		return;
+ 
++	ctx->flags |= E2F_FLAG_PROBLEMS_FIXED;
+ 	memset(((char *) journal->j_superblock) + V1_SB_SIZE, 0,
+ 	       ctx->fs->blocksize-V1_SB_SIZE);
+ 	mark_buffer_dirty(journal->j_sb_buffer);
+diff --git a/e2fsck/problem.c b/e2fsck/problem.c
+index 34a671e..4b25069 100644
+--- a/e2fsck/problem.c
++++ b/e2fsck/problem.c
+@@ -1276,12 +1276,12 @@ static struct e2fsck_problem problem_table[] = {
+ 	/* Inode extent tree could be shorter */
+ 	{ PR_1E_CAN_COLLAPSE_EXTENT_TREE,
+ 	  N_("@i %i @x tree (at level %b) could be shorter.  "),
+-	  PROMPT_FIX, PR_NO_OK | PR_PREEN_NO | PR_PREEN_OK },
++	  PROMPT_FIX, PR_NO_OK | PR_PREEN_NO | PR_PREEN_OK | PR_NOT_A_FIX },
+ 
+ 	/* Inode extent tree could be narrower */
+ 	{ PR_1E_CAN_NARROW_EXTENT_TREE,
+ 	  N_("@i %i @x tree (at level %b) could be narrower.  "),
+-	  PROMPT_FIX, PR_NO_OK | PR_PREEN_NO | PR_PREEN_OK },
++	  PROMPT_FIX, PR_NO_OK | PR_PREEN_NO | PR_PREEN_OK | PR_NOT_A_FIX },
+ 
+ 	/* Pass 2 errors */
+ 
+@@ -2166,6 +2166,7 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
+ 		reconfigure_bool(ctx, ptr, key, PR_NO_NOMSG, "no_nomsg");
+ 		reconfigure_bool(ctx, ptr, key, PR_PREEN_NOHDR, "preen_noheader");
+ 		reconfigure_bool(ctx, ptr, key, PR_FORCE_NO, "force_no");
++		reconfigure_bool(ctx, ptr, key, PR_NOT_A_FIX, "not_a_fix");
+ 		profile_get_integer(ctx->profile, "options",
+ 				    "max_count_problems", 0, 0,
+ 				    &ptr->max_count);
+@@ -2283,7 +2284,8 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
+ 	if (ptr->flags & PR_AFTER_CODE)
+ 		answer = fix_problem(ctx, ptr->second_code, pctx);
+ 
+-	if (answer && (ptr->prompt != PROMPT_NONE))
++	if (answer && (ptr->prompt != PROMPT_NONE) &&
++	    !(ptr->flags & PR_NOT_A_FIX))
+ 		ctx->flags |= E2F_FLAG_PROBLEMS_FIXED;
+ 
+ 	return answer;
+diff --git a/e2fsck/problemP.h b/e2fsck/problemP.h
+index 7944cd6..63bb8df 100644
+--- a/e2fsck/problemP.h
++++ b/e2fsck/problemP.h
+@@ -44,3 +44,4 @@ struct latch_descr {
+ #define PR_CONFIG	0x080000 /* This problem has been customized
+ 				    from the config file */
+ #define PR_FORCE_NO	0x100000 /* Force the answer to be no */
++#define PR_NOT_A_FIX	0x200000 /* Yes doesn't mean a problem was fixed */
+diff --git a/e2fsck/unix.c b/e2fsck/unix.c
+index eb9f311..9e4d31a 100644
+--- a/e2fsck/unix.c
++++ b/e2fsck/unix.c
+@@ -1901,11 +1901,23 @@ no_journal:
+ 		fix_problem(ctx, PR_6_IO_FLUSH, &pctx);
+ 
+ 	if (was_changed) {
+-		exit_value |= FSCK_NONDESTRUCT;
+-		if (!(ctx->options & E2F_OPT_PREEN))
+-			log_out(ctx, _("\n%s: ***** FILE SYSTEM WAS "
+-				       "MODIFIED *****\n"),
++		int fs_fixed = (ctx->flags & E2F_FLAG_PROBLEMS_FIXED);
++
++		if (fs_fixed)
++			exit_value |= FSCK_NONDESTRUCT;
++		if (!(ctx->options & E2F_OPT_PREEN)) {
++#if 0	/* Do this later; it breaks too many tests' golden outputs */
++			log_out(ctx, fs_fixed ?
++				_("\n%s: ***** FILE SYSTEM ERRORS "
++				  "CORRECTED *****\n") :
++				_("%s: File system was modified.\n"),
+ 				ctx->device_name);
++#else
++			log_out(ctx,
++				_("\n%s: ***** FILE SYSTEM WAS MODIFIED *****\n"),
++				ctx->device_name);
++#endif
++		}
+ 		if (ctx->mount_flags & EXT2_MF_ISROOT) {
+ 			log_out(ctx, _("%s: ***** REBOOT SYSTEM *****\n"),
+ 				ctx->device_name);
+diff --git a/tests/f_collapse_extent_tree/expect.1 b/tests/f_collapse_extent_tree/expect.1
+index e2eb65e..8165a58 100644
+--- a/tests/f_collapse_extent_tree/expect.1
++++ b/tests/f_collapse_extent_tree/expect.1
+@@ -13,4 +13,4 @@ Pass 5: Checking group summary information
+ 
+ test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+ test_filesys: 12/128 files (0.0% non-contiguous), 19/512 blocks
+-Exit status is 1
++Exit status is 0
+diff --git a/tests/f_compress_extent_tree_level/expect.1 b/tests/f_compress_extent_tree_level/expect.1
+index a359c99..dd33f63 100644
+--- a/tests/f_compress_extent_tree_level/expect.1
++++ b/tests/f_compress_extent_tree_level/expect.1
+@@ -20,4 +20,4 @@ Pass 5: Checking group summary information
+ 
+ test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+ test_filesys: 12/128 files (8.3% non-contiguous), 26/512 blocks
+-Exit status is 1
++Exit status is 0
+diff --git a/tests/f_convert_bmap/expect.1 b/tests/f_convert_bmap/expect.1
+index 7d2ca86..c387962 100644
+--- a/tests/f_convert_bmap/expect.1
++++ b/tests/f_convert_bmap/expect.1
+@@ -23,4 +23,4 @@ Pass 5: Checking group summary information
+ 
+ test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+ test_filesys: 12/128 files (8.3% non-contiguous), 570/2048 blocks
+-Exit status is 1
++Exit status is 0
+diff --git a/tests/f_convert_bmap_and_extent/expect.1 b/tests/f_convert_bmap_and_extent/expect.1
+index 7af91aa..c86c571 100644
+--- a/tests/f_convert_bmap_and_extent/expect.1
++++ b/tests/f_convert_bmap_and_extent/expect.1
+@@ -30,4 +30,4 @@ Pass 5: Checking group summary information
+ 
+ test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+ test_filesys: 13/128 files (15.4% non-contiguous), 574/2048 blocks
+-Exit status is 1
++Exit status is 0
+diff --git a/tests/f_extent_htree/expect.1 b/tests/f_extent_htree/expect.1
+index 223ca69..ea48405 100644
+--- a/tests/f_extent_htree/expect.1
++++ b/tests/f_extent_htree/expect.1
+@@ -26,4 +26,4 @@ test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+            0 sockets
+ ------------
+          343 files
+-Exit status is 1
++Exit status is 0
+diff --git a/tests/f_jnl_errno/expect.1 b/tests/f_jnl_errno/expect.1
+index c572951..4134234 100644
+--- a/tests/f_jnl_errno/expect.1
++++ b/tests/f_jnl_errno/expect.1
+@@ -6,4 +6,4 @@ Pass 5: Checking group summary information
+ 
+ test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+ test_filesys: 11/2048 files (9.1% non-contiguous), 1330/8192 blocks
+-Exit status is 1
++Exit status is 0
+diff --git a/tests/f_journal/expect.1 b/tests/f_journal/expect.1
+index a202c80..0a18654 100644
+--- a/tests/f_journal/expect.1
++++ b/tests/f_journal/expect.1
+@@ -59,4 +59,4 @@ Pass 5: Checking group summary information
+ 
+ test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+ test_filesys: 53/2048 files (1.9% non-contiguous), 1409/8192 blocks
+-Exit status is 1
++Exit status is 0
+diff --git a/tests/f_orphan/expect.1 b/tests/f_orphan/expect.1
+index eddc1f8..087ebee 100644
+--- a/tests/f_orphan/expect.1
++++ b/tests/f_orphan/expect.1
+@@ -11,4 +11,4 @@ Pass 5: Checking group summary information
+ 
+ test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+ test_filesys: 12/2048 files (0.0% non-contiguous), 1303/8192 blocks
+-Exit status is 1
++Exit status is 0
+diff --git a/tests/f_orphan_extents_inode/expect.1 b/tests/f_orphan_extents_inode/expect.1
+index 2eaab78..5d713b3 100644
+--- a/tests/f_orphan_extents_inode/expect.1
++++ b/tests/f_orphan_extents_inode/expect.1
+@@ -7,4 +7,4 @@ Pass 5: Checking group summary information
+ 
+ test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+ test_filesys: 12/16 files (0.0% non-contiguous), 21/100 blocks
+-Exit status is 1
++Exit status is 0
+diff --git a/tests/f_rehash_dir/expect.1 b/tests/f_rehash_dir/expect.1
+index 6076765..c1449ba 100644
+--- a/tests/f_rehash_dir/expect.1
++++ b/tests/f_rehash_dir/expect.1
+@@ -7,4 +7,4 @@ Pass 5: Checking group summary information
+ 
+ test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+ test_filesys: 105/2048 files (2.9% non-contiguous), 336/512 blocks
+-Exit status is 1
++Exit status is 0
+diff --git a/tests/f_unsorted_EAs/expect.1 b/tests/f_unsorted_EAs/expect.1
+index 7d588d7..64b9045 100644
+--- a/tests/f_unsorted_EAs/expect.1
++++ b/tests/f_unsorted_EAs/expect.1
+@@ -8,4 +8,4 @@ Pass 5: Checking group summary information
+ 
+ test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+ test_filesys: 12/2048 files (0.0% non-contiguous), 1294/2048 blocks
+-Exit status is 1
++Exit status is 0
+-- 
+1.9.1
+
meta/recipes-devtools/e2fsprogs/e2fsprogs_1.43.4.bb +1 -0
index 153b3a1..5216c70 100644
@@ -9,6 +9,7 @@ SRC_URI += "file://acinclude.m4 \
             file://Revert-mke2fs-enable-the-metadata_csum-and-64bit-fea.patch \
             file://e2fsprogs-1.43-sysmacros.patch \
             file://mkdir_p.patch \
+            file://0001-e2fsck-exit-with-exit-status-0-if-no-errors-were-fix.patch \
 "
 
 SRC_URI_append_class-native = " file://e2fsprogs-fix-missing-check-for-permission-denied.patch"
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/3 wic: partition.py: Add fsck to avoid corrupt EXT file systems

This patch avoids the creation of a corrupt EXT file system.

Since there are no checks if a EXT file system was successfully created, this should add to prevent possible system failures.

---
 scripts/lib/wic/partition.py | 3 +++
 1 file changed, 3 insertions(+)
scripts/lib/wic/partition.py +3 -0
index 6ef8d7f..8e32afc 100644
@@ -286,6 +286,9 @@ class Partition():
             (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir)
         exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
 
+        mkfs_cmd = "fsck.%s -fy %s" % (self.fstype, rootfs)
+        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
+
     def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir,
                              native_sysroot, pseudo):
         """
Signature · 1 line
1.9.1
#2 lore raw

PATCH 3/3 meta: images: Add fsck to avoid corrupt EXT file systems

In reply to Daniel Schultz

This patch avoids the creation of a corrupt EXT file system.

Since there are no checks if a EXT file system was successfully created, this should add to prevent possible system failures.

---
 meta/classes/image_types.bbclass | 1 +
 1 file changed, 1 insertion(+)
meta/classes/image_types.bbclass +1 -0
index d2eb99d..66c643d 100644
@@ -74,6 +74,7 @@ oe_mkext234fs () {
 	# Create a sparse image block
 	dd if=/dev/zero of=${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.$fstype seek=$ROOTFS_SIZE count=$COUNT bs=1024
 	mkfs.$fstype -F $extra_imagecmd ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.$fstype -d ${IMAGE_ROOTFS}
+	fsck.$fstype -fy ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.$fstype
 }
 
 IMAGE_CMD_ext2 = "oe_mkext234fs ext2 ${EXTRA_IMAGECMD}"
Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH 3/3] meta: images: Add fsck to avoid corrupt EXT file systems

Quoted 3 lines · Daniel Schultz

Since there are no checks if a EXT file system was successfully created, this should add to prevent possible system failures.

Doesn't mkfs returns an exit code if it wasn't successful?

Ross

#4 lore raw

Re: [PATCH 3/3] meta: images: Add fsck to avoid corrupt EXT file systems

Am 20.03.2017 um 13:26 schrieb Burton, Ross:

Quoted 10 lines

On 20 March 2017 at 12:18, Daniel Schultz <[email protected] <mailto:[email protected]>> wrote:

Since there are no checks if a EXT file system was successfully created, this should add to prevent possible system failures.

Doesn't mkfs returns an exit code if it wasn't successful?

Yes, but it seems like mkfs can't handle everything.

"The htree (hash tree) indexes directory entries by hash to speed up random directory accesses. e2fsck can regenerate the indices, but the rest of e2fsprogs cannot create or maintain them."
[http://www.spinics.net/lists/linux-ext4/msg55702.html]

Currently, our boards have to reboot, because fsck exits with an error code of 1 at the first boot.

Quoted 1 line

Ross

Signature · 3 lines
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz
#5 lore raw

Re: [PATCH 3/3] meta: images: Add fsck to avoid corrupt EXT file systems

Quoted 4 lines · Daniel Schultz

Doesn't mkfs returns an exit code if it wasn't successful?

Quoted 2 lines

Yes, but it seems like mkfs can't handle everything.

Quoted 8 lines

"The htree (hash tree) indexes directory entries by hash to speed up random directory accesses. e2fsck can regenerate the indices, but the rest of e2fsprogs cannot create or maintain them."
[http://www.spinics.net/lists/linux-ext4/msg55702.html]

Currently, our boards have to reboot, because fsck exits with an error code of 1 at the first boot.

Fair enough, thanks.

Ross