OpenZFS 2.4.5 Fixes Lost Synchronous Writes After a Log Failure and Repair Errors During RAIDZ Expansion
The article's text, from Joho no Todai's page.
On December 4, the OpenZFS project released OpenZFS 2.4.5 as a stable version. Its Linux kernel support extends from 4.18–7.2 in version 2.4.4 to 4.18–7.3. FreeBSD support continues to cover releases from 13.3 and from 14.0 onward in their respective series.
The update changes the conditions under which the file system reports that a write succeeded.
A database, for example, expects a completed sync to mean that writes will survive a system crash. ZFS uses the ZFS Intent Log (ZIL) to make synchronous writes durable alongside transaction groups (TXGs), which apply ordinary writes in batches. After a crash, ZFS can replay the log on disk to recover synchronous writes whose TXGs had not yet synced.
According to the published fix, if writing a ZIL block fails, operations waiting for that block fall back to waiting for the regular TXG to sync. The problem lay in later log blocks.
OpenZFS 2.4.5: Synchronous writes after a log failure
| Unpatched development build | With the fix |
|---|---|
| After a ZIL (synchronous write log) write fails TXG: Transaction group that applies writes in batches | |
| A later log write succeeds and may report success despite an earlier error | Wait for the affected TXG to finish syncing |
| Crash before the TXG syncs | |
| Later acknowledged writes can be lost | Acknowledgment of later writes waits |
| Transient dedicated log device write error Crash recovery test with an unsynced TXG Acknowledged writes lost per run | |
| About 125 | 0 |
The previous code could fail to propagate a log block’s error to later blocks. As a result, fsync() calls or writes using O_DSYNC could report success despite an earlier log failure.
During crash recovery, log replay stops at a block it cannot read. If the regular TXG has not synced, even data that the application believed was safely written can be lost.
In the developer’s crash-recovery tests involving a transient log device write error, the unfixed development version lost about 125 acknowledged writes per run. The developer reported zero lost writes in testing after the patch.
The new code tracks the TXG associated with the failed log block. Until that TXG syncs, subsequent synchronous writes also wait for regular TXG syncing. The additional wait applies only after a log block error.
Changing when ZFS reports success protects the durability applications expect. Making the notification meaningful took precedence over completing the operation sooner.
RAIDZ expansion could prevent repair of recoverable data
RAIDZ distributes data and recovery information, called parity, across multiple disks. RAIDZ1, for example, is designed to recover from a single disk failure. A scrub verifies stored data against its checksums and uses redundancy to repair corruption it finds.
When a disk is added to expand RAIDZ capacity, ZFS gradually moves existing data to a layout that includes the new disk. During expansion, migrated and unmigrated areas coexist.
One issue described by the developers affected scrubbing and self-healing reads for corrupted blocks that span the boundary between layouts. Fault attribution used the new disk count and could misidentify the position corresponding to a failed disk in the old layout.
A reconstruction could count two faults even when only one disk held corrupt data. That could cause ZFS to report a permanent error for data that could be recovered from parity.
A second problem involved the ordering of repair and migration. If the target region was unlocked before a repair write finished, expansion could move the stale data. A delayed repair could also write to a location that expansion had already reused.
Version 2.4.5 uses the RAIDZ width of the relevant layout for fault attribution and keeps the region locked until the repair write completes. It also waits for I/O to the old layout to finish before updating expansion progress.
OpenZFS 2.4.5: Data recovery tests in virtual machines
| Test environment | Before the fix | After the fix |
|---|---|---|
| RAIDZ1 expansion: One disk had corruption in the old layout Repair of a block spanning both layouts Before column includes the range-lock fix | ||
| Ubuntu 24.04 Debug build (With checks enabled) | 20 of 20 failed | 20 of 20 passed |
| Ubuntu 24.04 Regular build | 10 of 10 failed | 10 of 10 passed |
| FreeBSD 15.1 Debug build | 10 of 10 failed | 10 of 10 passed |
| Sequential mirror reconstruction Involving a disk with missed writes Automatic post-rebuild scrub was off Readback from the new disk alone | ||
| Debian 13 Debug build | 3 of 3 failed | 5 of 5 passed |
| FreeBSD 15.1 Debug build | 3 of 3 failed | 5 of 5 passed |
The developers tested repairs of blocks spanning the boundary on Ubuntu 24.04 and FreeBSD 15.1 virtual machines. With the range-lock fix in place but before the fault-attribution fix, all runs failed: 20 on a Linux debug build, ten on a regular Linux build, and ten on a FreeBSD debug build. After both fixes, all 20, ten, and ten runs passed, respectively.
The developers said the fix does not cover new silent corruption, meaning corruption with no explicit error, during RAIDZ1 expansion. A block across the boundary at the time of the fault can contain corruption from both layouts. They said recovering it would require a separate change.
A redundant storage design needs to detect corrupted data and reconstruct it in the right place. The ability to tolerate a failed disk still depends on handling the transition between layouts correctly.
Sequential reconstruction could copy stale data to a new mirror disk
The release also fixes a data integrity problem during sequential reconstruction in mirrors, which keep copies of data on several disks.
The developers’ explanation describes a mirror in which a disk had temporarily been offline and missed writes. Sequential reconstruction could use a disk with missed writes as its source, leaving stale data on the replacement disk.
Sequential reconstruction leaves checksum verification to the scrub that follows. By default the scrub starts after reconstruction and can use redundancy to correct bad copies. If that scrub is disabled or fails to run, the new disk may be unable to serve the right data on its own.
The developers tested data readback from the replacement disk on Debian 13 and FreeBSD 15.1 virtual machines. Before the patch, all three runs on each OS’s debug build failed. The pool reported no known data errors after reconstruction, yet files were missing when read from the replacement disk alone.
The fix prefers source disks with an empty dirty time log (DTL), which records missed writes. It can still use a disk with missed writes if no other source is available. After the patch, readback passed all five runs on each OS.
Even after reconstruction completes, there is still the question of whether the copy is correct. For sequential reconstruction in particular, operations need to account for the integrity check that follows.
When the fixes reach deployed systems
Version 2.4.5 also fixes a double free when cloning blocks pending freeing, an access to freed memory while retrying a synchronous L2ARC cache read, and repeated work by the sync thread while a storage pool is suspended.
At 07:35 UTC on December 4, a Debian bug notice said zfs-linux 2.4.5-1 fixed the failure to build the ZFS kernel module on Linux 7.3 in the source package for Debian unstable. The package incorporates the upstream release. The notice said it was scheduled to enter the Debian archive.
Commercial NAS products also use ZFS data protection features. QNAP’s QuTS hero, for example, offers RAIDZ expansion, checksum verification, and self-healing. Users of those products can select their model in the manufacturer’s download center and check what the offered update includes. The date of an OpenZFS release alone does not establish which products have received the fixes.
These three fixes address gaps between what the file system reported about successful writes or recovered redundancy and what was actually stored. Adding disks can protect data, and so can checking that the data can be read back correctly after a failure.
