# K2146–K2150 Shutdown Storage Flush Contract (`shutdown_io.flush`) ## Purpose and Invariant - **Feature**: `shutdown_io.flush` (`K2146–K2150`) - **Invariant**: Completed storage flush and mere process/host quit are distinct events (`Tamamlanan flush ile süreç quit ayrıdır`). - **Scope**: Models ordered shutdown storage flushing (`Data -> Metadata -> Journal`) after write admission has quiesced, and refuses the clean-shutdown label whenever any flush stage fails with `EIO` (`5`) or `ETIMEDOUT` (`110`), is skipped out of order, or is claimed via a bare process quit. ## State Machine (`Phase`) | Phase | Code | Meaning | | --- | --- | --- | | `Idle` | `0` | Quiesced write gate confirmed; awaiting `Stage::Data` flush | | `DataFlushed` | `1` | Dirty data extents flushed (`flushed_stages |= 1`) | | `MetadataFlushed` | `2` | Inode/directory metadata flushed (`flushed_stages |= 2`) | | `JournalFlushed` | `3` | Journal commit barrier flushed (`flushed_stages |= 4`, `ALL_STAGES_MASK = 0b111`) | | `CleanReady` | `4` | All three stages flushed without fault and `clean_granted == true` | | `DegradedAbort` | `5` | Flush stage encountered `Fault::IoError` (`EIO = 5`) or `Fault::Timeout` (`ETIMEDOUT = 110`); clean shutdown label permanently withheld | ## Error Codes (`Error`) - `NotQuiesced = 1`: `FlushCoordinator::new(false)` refused before write quiesce completes. - `Order = 2`: Out-of-order or duplicate stage flush refused. - `InvalidFlush = 3`: Zero block count, zero journal sequence, zero digest, or invalid fault injection refused. - `IoError = 4`: Storage flush failed with `EIO` (`5`); transitions to `Phase::DegradedAbort`. - `Timeout = 5`: Storage flush timed out with `ETIMEDOUT` (`110`); transitions to `Phase::DegradedAbort`. - `ProcessQuitNotFlush = 6`: `claim_clean_shutdown(true)` refused because process/host termination is not a storage flush. - `CleanClaimRefused = 7`: `claim_clean_shutdown(false)` refused when any stage is missing or `fault_count != 0`. ## Storage adapter and remaining guest evidence `os-shutdown-io/src/flush_io.rs` now issues backend writes and flush barriers in Data, Metadata, Journal order. It validates all LBAs, capacities and aliases before the first write, requires a fully drained `QuiesceGate`, and issues a private clean receipt only after all three barriers complete. EIO or timeout stops subsequent I/O and prevents reuse of the same coordinator. The backend retains responsibility for DMA ownership and reset after a timeout. The adapter is tested with an explicit host backend fixture. The existing K2150 guest candidate still runs the earlier state model with caller-supplied counts and digests; its attached block disk is read-only. It does not prove actual storage FLUSH completion. The feature matrix checker rejects its `model-component-only` acceptance scope. Native device integration, captured request/completion records and device EIO/timeout cases must pass before K2150 can receive guest acceptance. Process exit, modeled counters and host fixtures cannot satisfy that requirement.