// K2441-K2445: fault_matrix.resources — ENOSPC ve quota matrisi // Invariant: Her tahsis durağı hata kabulüne bağlıdır // Positive: Frame handle queue inode tükenir // Counterexample: Hata sonrası kaynağın yarısı kalır // Acceptance: Başlangıç son sahiplik aynı pub const FAULT_MATRIX_RESOURCES_SCHEMA: &str = "turkos.os.fault_matrix.resources.v1"; pub const FAULT_MATRIX_RESOURCES_INVARIANT: &str = "Her tahsis durağı hata kabulüne bağlıdır"; pub const FAULT_MATRIX_RESOURCES_POSITIVE: &str = "Frame handle queue inode tükenir"; pub const FAULT_MATRIX_RESOURCES_COUNTEREXAMPLE: &str = "Hata sonrası kaynağın yarısı kalır"; pub const FAULT_MATRIX_RESOURCES_ACCEPTANCE: &str = "Başlangıç son sahiplik aynı"; pub const EXPECTED_EXHAUSTED_RESOURCE_CLASSES: u32 = 4; pub const EXPECTED_ROLLBACK_POINTS_VERIFIED: u32 = 8; pub const EXPECTED_OWNERSHIP_PARITY_RECORDS: u32 = 4; pub const EXPECTED_HALF_ALLOCATED_LEAKS: u32 = 0; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum FaultMatrixResourcesError { HalfAllocatedResourceRemainsAfterError = 1, AllocationStopUnboundToFaultAcceptance = 2, InitialFinalOwnershipMismatch = 3, ExhaustedResourceClassesMismatch = 4, RollbackPointsVerifiedMismatch = 5, OwnershipParityRecordsMismatch = 6, ZeroResourcesEpoch = 7, NonMonotonicResourcesEpoch = 8, ZeroResourcesQuotaDigest = 9, UnboundFaultMatrixResourcesDigest = 10, AlreadyCommitted = 11, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct FaultMatrixResourcesRequest { pub half_allocated_resource_remains_after_error: bool, pub allocation_stop_unbound_to_fault_acceptance: bool, pub initial_final_ownership_identical: bool, pub exhausted_resource_classes: u32, pub rollback_points_verified: u32, pub ownership_parity_records: u32, pub resources_epoch: u64, pub previous_resources_epoch: u64, pub resources_quota_digest: u64, pub resources_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct FaultMatrixResourcesReceipt { pub exhausted_resource_classes: u32, pub rollback_points_verified: u32, pub ownership_parity_records: u32, pub half_allocated_leaks: u32, pub initial_final_ownership_identical: bool, pub resources_epoch: u64, pub resources_quota_digest: u64, pub receipt_digest: u64, } pub const fn compute_fault_matrix_resources_binding_digest( exhausted_resource_classes: u32, rollback_points_verified: u32, ownership_parity_records: u32, half_allocated_leaks: u32, resources_epoch: u64, resources_quota_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2445_464d_5245_5331).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (exhausted_resource_classes as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (rollback_points_verified as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (ownership_parity_records as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (half_allocated_leaks as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ resources_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ resources_quota_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct FaultMatrixResourcesCoordinator { committed: bool, committed_total: u64, rejected_total: u64, rollback_integrity_refusals: u64, resource_accounting_refusals: u64, committed_receipt: Option, } impl FaultMatrixResourcesCoordinator { pub const fn new() -> Self { Self { committed: false, committed_total: 0, rejected_total: 0, rollback_integrity_refusals: 0, resource_accounting_refusals: 0, committed_receipt: None, } } pub fn is_committed(&self) -> bool { self.committed } pub fn committed_total(&self) -> u64 { self.committed_total } pub fn rejected_total(&self) -> u64 { self.rejected_total } pub fn rollback_integrity_refusals(&self) -> u64 { self.rollback_integrity_refusals } pub fn resource_accounting_refusals(&self) -> u64 { self.resource_accounting_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_enospc_quota_matrix( &mut self, req: &FaultMatrixResourcesRequest, ) -> Result { if self.committed { self.rejected_total += 1; return Err(FaultMatrixResourcesError::AlreadyCommitted); } if req.half_allocated_resource_remains_after_error { self.rejected_total += 1; self.rollback_integrity_refusals += 1; return Err(FaultMatrixResourcesError::HalfAllocatedResourceRemainsAfterError); } if req.allocation_stop_unbound_to_fault_acceptance { self.rejected_total += 1; self.rollback_integrity_refusals += 1; return Err(FaultMatrixResourcesError::AllocationStopUnboundToFaultAcceptance); } if !req.initial_final_ownership_identical { self.rejected_total += 1; self.rollback_integrity_refusals += 1; return Err(FaultMatrixResourcesError::InitialFinalOwnershipMismatch); } if req.exhausted_resource_classes != EXPECTED_EXHAUSTED_RESOURCE_CLASSES { self.rejected_total += 1; self.resource_accounting_refusals += 1; return Err(FaultMatrixResourcesError::ExhaustedResourceClassesMismatch); } if req.rollback_points_verified != EXPECTED_ROLLBACK_POINTS_VERIFIED { self.rejected_total += 1; self.resource_accounting_refusals += 1; return Err(FaultMatrixResourcesError::RollbackPointsVerifiedMismatch); } if req.ownership_parity_records != EXPECTED_OWNERSHIP_PARITY_RECORDS { self.rejected_total += 1; self.resource_accounting_refusals += 1; return Err(FaultMatrixResourcesError::OwnershipParityRecordsMismatch); } if req.resources_epoch == 0 { self.rejected_total += 1; return Err(FaultMatrixResourcesError::ZeroResourcesEpoch); } if req.resources_epoch <= req.previous_resources_epoch { self.rejected_total += 1; return Err(FaultMatrixResourcesError::NonMonotonicResourcesEpoch); } if req.resources_quota_digest == 0 { self.rejected_total += 1; return Err(FaultMatrixResourcesError::ZeroResourcesQuotaDigest); } let expected_binding = compute_fault_matrix_resources_binding_digest( req.exhausted_resource_classes, req.rollback_points_verified, req.ownership_parity_records, EXPECTED_HALF_ALLOCATED_LEAKS, req.resources_epoch, req.resources_quota_digest, ); if req.resources_binding_digest != expected_binding { self.rejected_total += 1; self.resource_accounting_refusals += 1; return Err(FaultMatrixResourcesError::UnboundFaultMatrixResourcesDigest); } self.committed = true; self.committed_total += 1; let receipt = FaultMatrixResourcesReceipt { exhausted_resource_classes: req.exhausted_resource_classes, rollback_points_verified: req.rollback_points_verified, ownership_parity_records: req.ownership_parity_records, half_allocated_leaks: EXPECTED_HALF_ALLOCATED_LEAKS, initial_final_ownership_identical: true, resources_epoch: req.resources_epoch, resources_quota_digest: req.resources_quota_digest, receipt_digest: expected_binding ^ 0x2445_ACE0_5245_5331, }; self.committed_receipt = Some(receipt); Ok(receipt) } }