Start atomic-commit case of sync_super()

In atomic-commit, sync_super() should write delta. This uses
force_delta() hack for now.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Start replay() with log_bnode_root() log

This adds logmap and "replay" command (for now) to tux3 to start
replay work.  Then adds replay_bnode_root() to replay LOG_BNODE_ROOT.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Add put_super() to unload sb

This cleans expected dirty buffers. And if there is still dirty
buffers (or something) debugging code can catch it.

Also, this also cleanups codes.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Move writing bitmap inode from save_inode() to rollup for atomic-commit

In atomic-commit case, bitmap inode is written in rollup stage. So,
this remove it from sync_inodes(). Then, all flushing codes for
atomic-commit are moved to do_commit().

With this change, bitmap inode may not be written after mkfs done
(i.e. open_inode() may fail). To handle this case, this adds basically

	inode = iget()
	if (not found inode)
		inode = create_inode()

which is called "iget_or_create_inode()".

For now, the user of iget_or_create_inode() is only bitmap inode.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Replay log_balloc() log

To replay log_balloc log, we have to separate replay() to 2 stages.

1. physical update like bnode, etc.
2. logical update like bitmap data pages, etc.

This separates to do it, then cleanup.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix replay_update_bitmap()

There may be no block-fork on replay though, we have to mark bitmap
buffer as dirty for sb->rollup, not just mark as dirty.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix reserve_superblock() in make_tux3()

reserve_superblock() is a bit tricky. It wants to reserve the blocks
early before being grabbed by others.  But allocating blocks for this
delta must be after sb->delta (or ->rollup) increment. Otherwise,
rollup and delta may write the both of bitmap data and balloc log in
this commit.

So, this provide the callback to do it.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Replay logblock allocation log

We have to reserve logblock as allocated. sb->logchain's block address
has address to do it. We use it like balloc log and update bitmap in
replay stage2.

FIXME: Now, this is using address array to know logblock address,
because logchain is reverse order. We would want to rewrite it with
more efficient way, instead reparse logchain for each stages.

We will revisit later if atomic-commit is more completed.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Add debugging codes for atomic commit

This adds trace() for debugging atomic commit. And to issue DELTA or
ROLLUP explicitly, this also adds new "delta" and "rollup" to tux3
command.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Replay log_leaf_redirect() log

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Replay log_bnode_redirect() log

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Replay log_bnode_update() log

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Fix replay_load_logblocks() and prepare for future logging

Now replay_load_logblocks() is calling blockput() while loading
blocks. It means memory pressure might free buffer.

To fix it, this pins buffer until replay finishes.

And we have to prepare for future logging after replay. This updates
sb->logthis and sb->lognext for it.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cleanup log.c

"logsize" uses log_ prefix as log_size, and use it everywhere instead of
hard coded size.

And log_begin() and log_end() are not needed to extern.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Add LOG_ROLLUP and LOG_DELTA log

For now, We have to know where is the log that rollup was already done
or not. To know it, this adds LOG_ROLLUP. And just for debugging,
LOG_DELTA is added (even if delta was empty, we will write
LOG_DELTA.).

LOG_ROLLUP is an initial log on rollup.
LOG_DELTA is an initial log on delta.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Prepare to use LOG_ROLLUP log

We have to know whether there is LOG_ROLLUP or not, and position of it.
Also, we are already makeing block address array for logblock, but it
is doing for each the replay stage.

So, this prepares both of block address and LOG_ROLLUP check in early
as replay_prepare().

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Use LOG_ROLLUP to check whether we have to replay this log block or not

If log is before latest rollup, those were already applied to FS. So,
we must not replay those.

To do it, this uses ->rollup_{pos,index}.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Rename retire_bfree() to apply_defered_bfree()

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Add LOG_BFREE_RELOG to prevent complex log block retire and replay

To retire log block is a bit complex.

For example, when can we free log block? Usually past log records are
releasable on rollup. But, if the record type was bfree after rollup
(say LOG_BFREE_ON_ROLLUP), we can't free that log block until after
rollup was committed. Because bfree of LOG_BFREE_ON_ROLLUP is still
not applied on this rollup (it is flused to bitmap data on next rollup).

So, we don't need to replay almost all logs, but we have to replay
LOG_BFREE_ON_ROLLUP on the past log blocks before latest rollup.

To prevent this complexity, we are logging LOG_BFREE_ON_ROLLUP on this
rollup as LOG_BFREE_RELOG again. With this, we can release
LOG_BFREE_ON_ROLLUP, and furthermore, we don't need to keep past log
blocks before this rollup at all. (log block itself is also logged as
LOG_BFREE_RELOG to free)

To do above, this patch adds LOG_BFREE_RELOG at first.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Use LOG_BFREE_RELOG to obsolete past rollup cycle

This obsoletes past rollup cycle by LOG_BFREE_RELOG. So, this removes
variables for managing previous rollup cycle.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>