libxfs: support reproducible filesystems using deterministic time/seed
Add support for reproducible filesystem creation through two environment
variables that enable deterministic behavior when building XFS filesystems.
SOURCE_DATE_EPOCH support:
When SOURCE_DATE_EPOCH is set, use its value for all filesystem timestamps
instead of the current time. This follows the reproducible builds
specification (https://reproducible-builds.org/specs/source-date-epoch/)
and ensures consistent inode timestamps across builds.
DETERMINISTIC_SEED support:
When DETERMINISTIC_SEED=1 is set, return a fixed seed value (0x53454544 =
"SEED") from get_random_u32() instead of reading from /dev/urandom.
get_random_u32() seems to be used mostly to set inode generation number, being
fixed should not be create collision issues at mkfs time.
The implementation introduces two helper functions to minimize changes
to existing code:
- current_fixed_time(): Parses and caches SOURCE_DATE_EPOCH on first
call. Returns fixed timestamp when set, falls back to gettimeofday() on
parse errors or when unset.
- get_deterministic_seed(): Checks for DETERMINISTIC_SEED=1 environment
variable on first call, and returns a fixed seed value (0x53454544).
Falls back to getrandom() when unset.
- Both helpers use one-time initialization to avoid repeated getenv() calls.
- Both quickly exit and noop if environment is not set or has invalid
variables, falling back to original behaviour.
Example usage:
SOURCE_DATE_EPOCH=
1234567890 \
DETERMINISTIC_SEED=1 \
mkfs.xfs \
-m uuid=$EXAMPLE_UUID \
-p file=./rootfs \
disk1.img
This enables distributions and build systems to create bit-for-bit
identical XFS filesystems when needed for verification and debugging.
v1 -> v2:
- simplify deterministic seed by returning a fixed value instead
of using Middle Square Weyl Sequence PRNG
- fix timestamp type time_t -> time64_t
- fix timestamp initialization flag to allow negative epochs
- fix timestamp conversion type using strtoll
- fix timestamp conversion check to be sure the whole string was parsed
- print warning message when SOURCE_DATE_EPOCH is invalid
Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
xfs: centralize error tag definitions
From: Christoph Hellwig <hch@lst.de>
Source kernel commit:
71fa062196ae3abab790c91f1bdf09dcdc6fb1fe
Right now 5 places in the kernel and one in xfsprogs need to be updated
for each new error tag. Add a bit of macro magic so that only the
error tag definition and a single table, which reside next to each
other, need to be updated.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>