Using ZFS uberblock time to initialise system clock

Peter Jeremy <[email protected]> Sat, 9 May 2026 10:59:42 +1000
Newsgroups gmane.os.freebsd.devel.file-systems
Message-ID <[email protected]>
FreeBSD has provision to initialise the system TOD clock from a filesystem
timestamp if no hardware RTC provides a valid time (see inittodr() called
from vfs_mountroot() or nfs_mountroot()).  This has support for UFS and NFS
root filesystems but not ZFS.

ZFS has a suitable timestamp in its uberblock (ub_timestamp) so it should
just be a matter of plumbing that timestamp through.  Digging into the code,
the most obvious problem is that ZFS doesn't initialise mnt_time in struct
mount when the filesystem is mounted.  So I tried patching zfs_domount() to
initialise mnt_time.  That solved the plumbing problem but revealed that, by
the time zfs_domount() is called on the root filesystem, ub_timestamp has
been "updated" to the (uninitialised) system clock.

Before I spend too much more time digging into this, has anyone else dug into
where the uberblock is updated during the root mount?

-- 
Peter Jeremy
signature.asc (application/pgp-signature, 963 B)
-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEE7rKYbDBnHnTmXCJ+FqWXoOSiCzQFAmn+hvhfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldEVF
QjI5ODZDMzA2NzFFNzRFNjVDMjI3RTE2QTU5N0EwRTRBMjBCMzQACgkQFqWXoOSi
CzSs3Q//ackhKkOByOtdYjZIKqhw1Pd7B1hSAVDB04QDEF9Pn6rAeMAfFtYmltck
Fc2fZv4zQKTvR/kq9LVMWNdtoM5JU1k58gpxDCZkzRrnjA297yPhGsIQHhD+JHmD
6y6LaNUY3M1rBPtG2PrKJtzMTYZqGBj+BjNBxXmCididmSgIv56pNa1EJNf5ypJX
1bL/F13rd0KztNhZ311Ks1+h2snyDqvFrHVKeRofWNAv2Uqr78iZjKQ2NjBoPzYk
O5uQvglUxdR0Hew6C2bJ1iFmcf8Bzd0p2aMZhMEEFrlf90po6W+Bcrm311gwsU6K
V/4kAWwZfZiIyag30d9bPl3G1C+3rKYT+M0ZHzKfK0OxZsmEPHqWq0xS/vHfvr+4
jXEmdGgz9wCM0y3a4NxAU5VFWU0Yzn7OhkHkmORWOoVsVV/tfld1SgrVgVb56p4Q
L4EXBcbfRFjI9sXarIPXg6wBmY8VhI8Z+VLldIOHxfzGM4zYMiDmQIaQYE4ddceN
hQQ8dvToWCPYuIze4O814dGYP2S7hCqbF2KK+XcKZIyJmWcdwSk2ilSlRMe2Kh1B
xEa16VSrnDIHTXdnOggT9Yv1EmBv/+v5y6nRbprelhEZDxSO7VIBGkQg8G0EXV+e
mxXucaXxiurSzNeZBH3SYqsrbN22e0lZj+WJ/4CoGxuo0sS3zag=
=oIZM
-----END PGP SIGNATURE-----