Implement Soft Updates support for FreeBSD's ext2 filesystem, providing metadata write ordering to maintain filesystem consistency after unexpected system shutdowns without introducing a journal.
The implementation adds a dependency-management subsystem in ext2_softdep.c, ext2_softdep_subr.c, and ext2_softdep.h. It tracks prerequisite and dependent metadata operations, manages their lifecycle, and coordinates buffer writes so that dependent metadata is not committed before its prerequisites.
Integrate dependency-aware I/O operations, including ext2_dep_bwrite(), ext2_dep_bdwrite(), and ext2_dep_defer(), with the filesystem's existing buffer-cache operations. The subsystem also provides mechanisms to drive pending dependencies, process I/O completion, discard obsolete dependencies, and handle failed writes.
Integrate Soft Updates with the existing allocation and mapping paths:
- Block allocation: track allocation, mapping, publication, and rollback through the allocation-state transitions. Integrate dependency handling with block bitmap updates and block allocation routines.
- Indirect blocks: coordinate initialization and pointer updates so that indirect metadata is written in the required order before references to newly allocated blocks become durable.
- Inode management: incorporate dependency handling into inode allocation, initialization, and reclamation paths.
- Metadata updates: extend the ordering mechanism to filesystem metadata operations, including directory and block-mapping updates.
The implementation retains ext2's existing on-disk structures, allocation mechanisms, and buffer-cache architecture. It uses explicit dependencies between metadata updates to control their persistence order.
This establishes the foundation for asynchronous metadata updates while avoiding unsafe publication of partially initialized filesystem objects. Crash-consistency guarantees depend on completing the durability and error-handling verification of all allocation, mapping, and reclamation paths.
This works well because ext2 uses the on-disk s_last_orphan and i_dtime to keep a list of truncated and unlinked inodes similar to UFS' di_freelink, so e2fsck is able to recover dead inodes just fine.
Parts of this code were developed with AI assistance, using free LLM engines (space rabbit, poolside/laguna-s-2.1:free) which were available for free for a limited time.