This is a note to let you know that I've just added the patch titled ext4: avoid updating the superblock on a r/o mount if not needed to the 6.4-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: ext4-avoid-updating-the-superblock-on-a-r-o-mount-if-not-needed.patch and it can be found in the queue-6.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 2ef6c32a914b85217b44a0a2418e830e520b085e Mon Sep 17 00:00:00 2001 From: Theodore Ts'o <tytso@xxxxxxx> Date: Fri, 23 Jun 2023 10:18:51 -0400 Subject: ext4: avoid updating the superblock on a r/o mount if not needed From: Theodore Ts'o <tytso@xxxxxxx> commit 2ef6c32a914b85217b44a0a2418e830e520b085e upstream. This was noticed by a user who noticied that the mtime of a file backing a loopback device was getting bumped when the loopback device is mounted read/only. Note: This doesn't show up when doing a loopback mount of a file directly, via "mount -o ro /tmp/foo.img /mnt", since the loop device is set read-only when mount automatically creates loop device. However, this is noticeable for a LUKS loop device like this: % cryptsetup luksOpen /tmp/foo.img test % mount -o ro /dev/loop0 /mnt ; umount /mnt or, if LUKS is not in use, if the user manually creates the loop device like this: % losetup /dev/loop0 /tmp/foo.img % mount -o ro /dev/loop0 /mnt ; umount /mnt The modified mtime causes rsync to do a rolling checksum scan of the file on the local and remote side, incrementally increasing the time to rsync the not-modified-but-touched image file. Fixes: eee00237fa5e ("ext4: commit super block if fs record error when journal record without error") Cc: stable@xxxxxxxxxx Link: https://lore.kernel.org/r/ZIauBR7YiV3rVAHL@glitch Reported-by: Sean Greenslade <sean@xxxxxxxxxxxxxxxxxx> Signed-off-by: Theodore Ts'o <tytso@xxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/ext4/super.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5980,19 +5980,27 @@ static int ext4_load_journal(struct supe err = jbd2_journal_wipe(journal, !really_read_only); if (!err) { char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL); + __le16 orig_state; + bool changed = false; if (save) memcpy(save, ((char *) es) + EXT4_S_ERR_START, EXT4_S_ERR_LEN); err = jbd2_journal_load(journal); - if (save) + if (save && memcmp(((char *) es) + EXT4_S_ERR_START, + save, EXT4_S_ERR_LEN)) { memcpy(((char *) es) + EXT4_S_ERR_START, save, EXT4_S_ERR_LEN); + changed = true; + } kfree(save); + orig_state = es->s_state; es->s_state |= cpu_to_le16(EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS); + if (orig_state != es->s_state) + changed = true; /* Write out restored error information to the superblock */ - if (!bdev_read_only(sb->s_bdev)) { + if (changed && !really_read_only) { int err2; err2 = ext4_commit_super(sb); err = err ? : err2; Patches currently in stable-queue which might be from tytso@xxxxxxx are queue-6.4/ext4-turn-quotas-off-if-mount-failed-after-enabling-quotas.patch queue-6.4/ext4-fix-wrong-unit-use-in-ext4_mb_new_blocks.patch queue-6.4/ext4-fix-reusing-stale-buffer-heads-from-last-failed-mounting.patch queue-6.4/ext4-avoid-updating-the-superblock-on-a-r-o-mount-if-not-needed.patch queue-6.4/ext4-fix-wrong-unit-use-in-ext4_mb_clear_bb.patch queue-6.4/ext4-get-block-from-bh-in-ext4_free_blocks-for-fast-commit-replay.patch queue-6.4/ext4-only-update-i_reserved_data_blocks-on-successful-block-allocation.patch queue-6.4/ext4-fix-to-check-return-value-of-freeze_bdev-in-ext4_shutdown.patch