Re: Journaling: Surviving or allowing unclean shutdown?

Stephen C. Tweedie
2001-01-05T10:33:56Z

Hi,

On Fri, Jan 05, 2001 at 01:31:12AM +0100, Daniel Phillips wrote:
> "Stephen C. Tweedie" wrote:
> >
> Yes, and so long as your journal is not on another partition/disk things
> will eventually be set right. The combination of a partially updated
> filesystem and its journal is in some sense a complete, consistent
> filesystem.

Right.

> I'm curious - how does ext3 handle the possibility of a crash during
> journal recovery?

Recovery comes in two parts: replay of the log, and deletion of
orphaned inodes.

The log replay is fully idempotent: it just consists of writing the
appropriate log blocks to their home locations on disk. It doesn't
matter if you do those writes once, twice or a hundred times, you
still get the same result, so crashing mid-recovery and starting again
from scratch is perfectly safe.

Once that recovery is done, the filesystem is marked, atomically, to
be clean.

Secondly, we do the deletion of orphaned inodes. By this time, the
journal itself has been recovered so we are journaling our operations,
so each orphaned inode delete is being logged. A crash will recover
to a consistent state via the normal journaling transaction methods,
and will restart orphan recovery from where it left off.

Cheers,
Stephen