Linux EXT4 FS development
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Subject: [PATCH 08/23] ext4: fix inverted err_report_sec check in ext4_update_super()
Date: Wed, 11 Nov 2026 23:46:57 -0500	[thread overview]
Message-ID: <20261112044712.1577296-9-tytso@mit.edu> (raw)
In-Reply-To: <20261112044712.1577296-1-tytso@mit.edu>

When the first error is copied into the on-disk superblock,
ext4_update_super() is supposed to start the periodic error reporting
timer if it is not already running and err_report_sec is non-zero, as
the comment above the code says.  However, the check was inverted:

	if (!es->s_error_count && !sbi->s_err_report_sec)

With the default err_report_sec of 86400 the timer is therefore never
started when a clean file system records its first error, so the
"error count since last fsck" messages are not printed until the file
system is remounted.  Conversely, if the administrator disabled the
report by writing 0 to /sys/fs/ext4/<dev>/err_report_sec, the first
error arms the timer to fire immediately.

Drop the stray negation.  Also read s_err_report_sec only once, with
READ_ONCE(), since it can be changed concurrently via sysfs, so that
the value tested is the value used to arm the timer.

Fixes: d518215c2719 ("ext4: add sysfs attribute err_report_sec to control s_err_report timer")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 fs/ext4/super-test.c | 12 ++++++++++++
 fs/ext4/super.c      |  6 ++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/super-test.c b/fs/ext4/super-test.c
index 3fd7a4d86f31..abd844c8c29f 100644
--- a/fs/ext4/super-test.c
+++ b/fs/ext4/super-test.c
@@ -1305,6 +1305,18 @@ static void test_error_recording_and_update_super(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, le64_to_cpu(es->s_kbytes_written), 100ULL);
 	KUNIT_EXPECT_EQ(test, es->s_checksum, ext4_superblock_csum(es));
 
+	/* First recorded error arms the periodic error report timer */
+	KUNIT_EXPECT_TRUE(test, timer_pending(&sbi->s_err_report));
+
+	/* err_report_sec == 0 disables the timer even for a first error */
+	timer_delete_sync(&sbi->s_err_report);
+	es->s_error_count = 0;
+	sbi->s_err_report_sec = 0;
+	ext4_save_error_info_test(sb, EIO, 31, 4096, "third_fn", 333);
+	ext4_update_super_test(sb);
+	KUNIT_EXPECT_EQ(test, le32_to_cpu(es->s_error_count), 1U);
+	KUNIT_EXPECT_FALSE(test, timer_pending(&sbi->s_err_report));
+
 	/* Read-only superblock update must not touch s_wtime */
 	es->s_wtime = cpu_to_le32(123456U);
 	saved_wtime = es->s_wtime;
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 6cdcae00d569..5f704c43c901 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -6302,6 +6302,7 @@ static void ext4_update_super(struct super_block *sb)
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	struct ext4_super_block *es = sbi->s_es;
 	struct buffer_head *sbh = sbi->s_sbh;
+	unsigned long err_report_sec;
 
 	lock_buffer(sbh);
 	/*
@@ -6360,9 +6361,10 @@ static void ext4_update_super(struct super_block *sb)
 		 * Start the daily error reporting function if it hasn't been
 		 * started already and sbi->s_err_report_sec is not zero
 		 */
-		if (!es->s_error_count && !sbi->s_err_report_sec)
+		err_report_sec = READ_ONCE(sbi->s_err_report_sec);
+		if (!es->s_error_count && err_report_sec)
 			mod_timer(&sbi->s_err_report,
-					  jiffies + secs_to_jiffies(sbi->s_err_report_sec));
+				  jiffies + secs_to_jiffies(err_report_sec));
 		le32_add_cpu(&es->s_error_count, sbi->s_add_error_count);
 		sbi->s_add_error_count = 0;
 	}
-- 
2.56.0.542.g3ef89b7020-goog


  parent reply	other threads:[~2026-11-12  4:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  4:46 [PATCH 00/23] ext4: lots of misc bug fixes Theodore Ts'o
2026-11-12  4:46 ` [PATCH 01/23] ext4: only update s_mount_opts when EXT4_TUNE_FL_MOUNT_OPTS is set Theodore Ts'o
2026-11-12  4:46 ` [PATCH 02/23] ext4: return -EFSBADCRC when skipping a corrupt backup superblock Theodore Ts'o
2026-11-12  4:46 ` [PATCH 03/23] ext4: don't allow enabling casefold via EXT4_IOC_SET_TUNE_SB_PARAM Theodore Ts'o
2026-11-12  4:46 ` [PATCH 04/23] ext4: persist the htree hash seed when enabling dir_index online Theodore Ts'o
2026-11-12  4:46 ` [PATCH 05/23] ext4: enforce feature prerequisites when tuning a mounted fs Theodore Ts'o
2026-11-12  4:46 ` [PATCH 06/23] ext4: handle s_lastcheck_hi in the get/set tune superblock ioctls Theodore Ts'o
2026-11-12  4:46 ` [PATCH 07/23] ext4: pass missing ioctls through ext4_compat_ioctl Theodore Ts'o
2026-11-12  4:46 ` Theodore Ts'o [this message]
2026-11-12  4:46 ` [PATCH 09/23] ext4: fix err_report_sec_store() timer and value handling Theodore Ts'o
2026-11-12  4:46 ` [PATCH 10/23] ext4: fix inode table accounting in count_overhead() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 11/23] ext4: handle flex groups straddling s_first_meta_bg in online resize Theodore Ts'o
2026-11-12  4:47 ` [PATCH 12/23] ext4: reject EXT4_IOC_GROUP_ADD inputs larger than a block group Theodore Ts'o
2026-11-12  4:47 ` [PATCH 13/23] ext4: propagate ext4_alloc_group_tables() errors from ext4_resize_fs() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 14/23] ext4: reject online shrink before probing the device size Theodore Ts'o
2026-11-12  4:47 ` [PATCH 15/23] ext4: cap migrated extents at EXT_INIT_MAX_LEN Theodore Ts'o
2026-11-12  4:47 ` [PATCH 16/23] ext4: don't treat a handle restart as an error in finish_range() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 17/23] ext4: don't clobber the migration result in ext4_ext_migrate() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 18/23] ext4: fix EOF clamping of the range in mext_check_adjust_range() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 19/23] ext4: bound the MMP update and check intervals Theodore Ts'o
2026-11-12  4:47 ` [PATCH 20/23] ext4: fix MMP claim of a cleanly unmounted filesystem Theodore Ts'o
2026-11-12  4:47 ` [PATCH 21/23] ext4: fix device comparison overflow in ext4_getfsmap_dev_compare() Theodore Ts'o
2026-11-12  4:47 ` [PATCH 22/23] ext4: don't allocate over indirect branches that failed to load Theodore Ts'o
2026-11-12  4:47 ` [PATCH 23/23] ext4: don't stop EXT4_IOC_GET_ES_CACHE at uncached ranges Theodore Ts'o

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=20261112044712.1577296-9-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=linux-ext4@vger.kernel.org \
    /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