Crash consistency: fsck and journaling


Persistence

Overview
A crash scenario
If the computer crashed during write

What are all the possible inconsistent states that the FS can be in after the crash?

Crash Scenarios

Case 1: only the data block is updated
Case 2: only the inode is updated
Case 3: only data bitmap is updated
Case 4: Only inode and data bitmap updated
Case 5: Only inode and data block updated
Case 6: Only data bitmap and data block updated

The crash-consistency problem

Details
Solution 1: FSCK
Limitation of FSCK
Solution 2: Journaling (write-ahead logging)

Journaling

What to store?

When updating the disk, before making the actual writes to disk, the FS first writes a little note about what it is about to do, to the journal (or log, at well known location on disk).

Failures become recoverable:

The structure to be written to the journal/log
Sequence of operations
A better sequence of operations
Recover from a crash
Space requirement
Metadata Journaling
Summary