# 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`.