Eio_fs_chaos.PowerSourceA power cut at a place the test chooses.
let cut_at_seventh base =
let power = Power.v Lose_unsynced in
let hook (op : Op.t) =
if op.index = 7 then ignore (Power.cut power);
None
in
Eio_fs_chaos.wrap hook (Power.wrap power base)A cut keeps what the program made durable, and may lose the rest:
Eio.File.sync runs on its file;This is ext4 with data=writeback. The disk model at the end says which states a cut may leave, sector by sector.
macOS. Under ~os:`Macos the disk is APFS's, on a drive with a cache:
Eio.File.sync and the portable barriers of Eio_fs.Sync are fsync(2), which stops in that cache: alone, they make nothing durable;eio-fs.unix (Eio_fs_unix.sync_file, Eio_fs_unix.sync_dir, Eio_fs_unix.barrier) are F_FULLFSYNC: each makes its file or directory durable, and every fsync(2) before it, of any file;Windows. Under ~os:`Windows a cut keeps what it keeps on Linux: Eio.File.sync is FlushFileBuffers, and a directory barrier counts as Linux's, though eio_windows syncs no directory. What NTFS keeps of a directory on a power cut is not modelled: only a power-cut test on real Windows could tell it.
The type for a write or a directory change that no sync has made durable.
type policy = | Lose_unsyncedThe disk holds what the last syncs made durable, with the truncations made before a directory change they made durable.
*)| Keep of change -> boolThe disk also holds the changes for which the predicate holds, as far as the disk model allows. Keep (fun _ -> true) is a killed process: the disk keeps what the program saw.
The type for what a cut does with the changes not yet synced.
The type for power switches.
v ~os policy is a power switch whose cut leaves what policy says, as the disk of os (defaults to `Linux) allows.
wrap t base is base with its writes, syncs and directory changes tracked by t. What base holds when wrap is called is durable. base may be in memory or on disk; a hole in a file on disk counts as written zeros.
A change that reaches base other than through the wrapper, by name or from a process the program started, is kept by a cut as durable: the wrapper sees no other process's syncs. At or below a path the wrapper changed, the policy decides, starting from what base held there when the wrapper first changed it. Stop those processes before calling cut.
cut t cuts the power, if t has not cut it yet, and is the directory given to wrap, which now holds what the disk kept. An entry the cut spared keeps its inode and, on an in-memory base, the times of its version the disk kept. Every later operation through the wrapper fails. Called from the function given to Eio_fs_chaos.wrap, it cuts the power before that operation, in the middle of a run.