From: Showta Ishizaki <zakinko@snowrabbit.org>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>, Ali Ahmet Memis <ali@iusegentoo.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Showta Ishizaki <zakinko@snowrabbit.org>
Subject: [PATCH 3/4] ufs: let FreeBSD see that its soft updates journal is out of date
Date: Fri, 27 Nov 2026 14:22:30 +0900 (JST) [thread overview]
Message-ID: <20261127-ufs-suj-3-v1@snowrabbit.org> (raw)
In-Reply-To: <20261127-ufs-suj-0-v1@snowrabbit.org>
fsck on FreeBSD uses the journal of a filesystem with journaled soft
updates when the time stored with the journal is fs_mtime, and then does
not do the full check. FreeBSD sets fs_mtime at each read-write mount.
ufs does not, so after a crash of Linux fsck recovers from a journal
that has nothing of what Linux wrote, and marks the filesystem clean.
Set fs_mtime when the filesystem becomes read-write.
With only fs_clean cleared, fsck_ffs -p of FreeBSD 15.0 used the journal
and marked clean all eight of the copies from the first patch, and
fsck_ffs -fn then found 154 to 225 errors in each. With this it says
Journal timestamp does not match fs mount time
goes on to the full check, and asks for a manual fsck. This is about
fsck_ffs -p; I did not look at the background fsck of a filesystem with
soft updates only, or at gjournal.
Signed-off-by: Showta Ishizaki <zakinko@snowrabbit.org>
---
fs/ufs/super.c | 26 ++++++++++++++++++++++++++
fs/ufs/ufs_fs.h | 4 +++-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index c204af7ce..716867fac 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -599,6 +599,31 @@ static void ufs_put_cstotal(struct super_block *sb)
UFSD("EXIT\n");
}
+/*
+ * FreeBSD's fsck takes the soft updates journal as current when the time
+ * kept with it is fs_mtime, and then skips the full check. FreeBSD sets
+ * fs_mtime at each read-write mount; do the same, as the journal knows
+ * nothing about what is written here.
+ */
+static void ufs_44bsd_set_mtime(struct super_block *sb)
+{
+ struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
+ struct ufs_super_block_first *usb1 = ubh_get_usb_first(uspi);
+ struct ufs_super_block_third *usb3 = ubh_get_usb_third(uspi);
+ time64_t now = ktime_get_real_seconds();
+ __fs64 mtime;
+
+ /* Without these the place belongs to fields of the old superblock. */
+ if (uspi->fs_magic != UFS2_MAGIC &&
+ !(usb1->fs_flags & UFS_FLAGS_UPDATED))
+ return;
+ memcpy(&mtime, usb3->fs_un2.fs_44.fs_mtime, sizeof(mtime));
+ if (now == fs64_to_cpu(sb, mtime))
+ now++;
+ mtime = cpu_to_fs64(sb, now);
+ memcpy(usb3->fs_un2.fs_44.fs_mtime, &mtime, sizeof(mtime));
+}
+
/*
* FreeBSD keeps fs_clean at 0 and NetBSD at 2 or 0 while a filesystem is
* mounted read-write, and at 1 otherwise, so that their fsck checks it after
@@ -613,6 +638,7 @@ static void ufs_44bsd_set_active(struct super_block *sb)
return;
sbi->s_was_clean = usb1->fs_clean == UFS_FSCLEAN;
usb1->fs_clean = UFS_FSACTIVE;
+ ufs_44bsd_set_mtime(sb);
ubh_mark_buffer_dirty(USPI_UBH(sbi->s_uspi));
ubh_sync_block(USPI_UBH(sbi->s_uspi));
}
diff --git a/fs/ufs/ufs_fs.h b/fs/ufs/ufs_fs.h
index b8dc354ae..c5e9c6aab 100644
--- a/fs/ufs/ufs_fs.h
+++ b/fs/ufs/ufs_fs.h
@@ -937,7 +937,9 @@ struct ufs_super_block_third {
__fs32 fs_qfmask[2]; /* ~usb_fmask */
} fs_sunx86;
struct {
- __fs32 fs_sparecon[50];/* reserved for future constants */
+ __fs32 fs_sparecon[23];/* reserved for future constants */
+ __fs32 fs_mtime[2]; /* last mount or fsck time */
+ __fs32 fs_sparecon2[25];/* reserved for future constants */
__fs32 fs_contigsumsize;/* size of cluster summary array */
__fs32 fs_maxsymlinklen;/* max length of an internal symlink */
__fs32 fs_inodefmt; /* format of on-disk inodes */
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-11-27 5:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 5:22 [PATCH 0/4] ufs: fs_clean and fs_mtime of a 44bsd filesystem that is read-write Showta Ishizaki
2026-11-27 5:22 ` [PATCH 1/4] ufs: clear fs_clean of a 44bsd filesystem while it " Showta Ishizaki
2026-11-27 5:22 ` [PATCH 2/4] ufs: do not take a filesystem NetBSD has mounted for clean Showta Ishizaki
2026-11-27 5:22 ` Showta Ishizaki [this message]
2026-11-27 5:22 ` [PATCH 4/4] ufs: leave fs_clean of a 44bsd filesystem at 0 after an error Showta Ishizaki
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=20261127-ufs-suj-3-v1@snowrabbit.org \
--to=zakinko@snowrabbit.org \
--cc=ali@iusegentoo.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®