pub struct RunningTransaction<'a> {
tx: RefCell<Vec<(LogicalBlockAddress, Box<[u8; 4096]>)>>,
journal: Option<SpinLockGuard<'a, Journal>>,
tx_id: u64,
io: Option<JournalIO<'a>>,
debug_journal: bool,
pub ffs: &'a FastFileSystemInner,
}Expand description
Represents an in-progress file system transaction using write-ahead journaling.
A RunningTransaction buffers metadata updates to disk blocks before they
are permanently written, ensuring crash consistency. When a transaction is
committed, the buffered blocks are flushed to the journal area first. Once
the journal write completes, the updates are applied to the actual metadata
locations on disk.
Transactions are used to group file system changes atomically — either all updates in a transaction are committed, or none are, preventing partial updates.
§Fields
tx: A buffer that stores staged metadata writes as a list of (LBA, data) tuples.journal: A locked handle to the globalJournal, used during commit.tx_id: Unique identifier for the current transaction.io: The journal I/O interface used for block-level reads/writes.debug_journal: Enables logging of journal operations for debugging.ffs: A reference to the file system’s core structure.
Fields§
§tx: RefCell<Vec<(LogicalBlockAddress, Box<[u8; 4096]>)>>§journal: Option<SpinLockGuard<'a, Journal>>§tx_id: u64§io: Option<JournalIO<'a>>§debug_journal: bool§ffs: &'a FastFileSystemInnerImplementations§
Source§impl<'a> RunningTransaction<'a>
impl<'a> RunningTransaction<'a>
Sourcepub fn begin(
name: &str,
ffs: &'a FastFileSystemInner,
io: JournalIO<'a>,
debug_journal: bool,
) -> Self
pub fn begin( name: &str, ffs: &'a FastFileSystemInner, io: JournalIO<'a>, debug_journal: bool, ) -> Self
Begins a new journaled transaction.
Initializes the transaction state and prepares to buffer metadata writes.
§Parameters
name: A label for the transaction, useful for debugging.ffs: The file system core structure.io: The journal I/O interface for block operations.debug_journal: Enables verbose logging if set totrue.
Sourcepub fn write_meta(
&self,
lba: LogicalBlockAddress,
data: Box<[u8; 4096]>,
ty: &str,
)
pub fn write_meta( &self, lba: LogicalBlockAddress, data: Box<[u8; 4096]>, ty: &str, )
Buffers a metadata block modification for inclusion in the transaction.
The actual write is deferred until commit() is called.
§Parameters
lba: The logical block address where the metadata will eventually be written.data: A boxed page of data representing the new metadata contents.ty: A type string name of the metadata (for debugging).
Sourcepub fn commit(self) -> Result<(), KernelError>
pub fn commit(self) -> Result<(), KernelError>
Commits the transaction to the journal and applies changes to disk.
This method performs the following steps:
- Writes all staged metadata blocks to the journal region on disk.
- Updates the journal superblock.
- Checkpoint the journal.
§Returns
Ok(()): If the transaction was successfully committed and checkpointed.Err(KernelError): If an I/O or consistency error occurred.