tux3: Remove PTE modification for forked page

With copy-on-write aware ->page_mkwrite(), we don't need to update PFN
of PTE on faulted address (caller of ->page_mkwrite() takes care of it).

So, this removes the modification of PTE on faulted address from
current ->page_mkwrite() related code. (I.e. pass vma of faulted
address to page_cow_file(), and if vma is for faulted address, it
doesn't update PFN in that vma.)

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Add page forking page_cow_file() helper for ->page_mkwrite() handler

This copies helpers from tux3.

When do page forking, we have to update PFN in PTEs of target page. To
do it, this adds page_cow_file() helper (and page_cow_one()).

page_cow_file() takes old and new pages, and updates PFN on related
PTEs of oldpage to newpage. If orig_vma was passed, it excludes to
update PFN (caller of ->page_mkwrite() takes care of it).

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Remove page_cow_file() helper was moved to core

This removes page_cow_file() was moved to core. With this, we don't
need to hack of unexported functions anymore.

So, remove some hacks for it too.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Add handler for page truncation on truncate_inode_pages_range()

truncate_inode_pages_range() is assuming, FS has to wait the
PageWriteback(), but it is not true if page is handled by page forking
at least. (Also, data=journal may be able to do some if want.)  And
there are some unexported functions in truncate_inode_pages_range(),
so FS can't replace it with per-FS code.

So, this adds handler (->truncatepage) to allow implement per-FS way
to truncate and release page.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Replace own implements with ->truncatepage() handler

Currently, we are walking pages once before truncate_inode_pages_range()
(so, walking twice include truncate_inode_pages_range()).
And we forks the page to avoid to wait I/O if need.

With ->truncatepage() handler, we don't need to walk pages before
truncate_inode_pages_range() anymore.

In ->truncatepage(), we checks state of the page. If need page fork,
do it. If not need, do normal truncate page.

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

This adds the following 3 helpers for page forking.

	cow_replace_page_cache()
	cow_delete_from_page_cache()
	cow_clone_page()

cow_replace_page_cache(): this is similar to
replace_page_cache_page(), but using radix_tree_replace_slot(), and
page forking aware.

cow_delete_from_page_cache(): this is similar to
delete_from_page_cache(), but deleted page is still used for I/O, not
freeing.

cow_clone_page(): this makes copy of original page.

All of above needs to be in core, because of unexported functions.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Remove page forking helpers was moved to core

This removes the following helpers, and replaces new helpers

	tux3_replace_page_cache() => cow_replace_page_cache()
	tux3_delete_from_page_cache() => cow_delete_from_page_cache()
	clone_page() => cow_clone_page() + tux3_clone_page()

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Make save_sb() static

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Use bio_end_io_t instead of void (*end_io)(struct bio *, int)

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Add async I/O helper

To submit buffer_head easily, this adds APIs for it.

At first, renames some sync APIs

	blockio()	=> blockio_sync()
	devio()		=> devio_sync()

Then, adds async API as blockio().

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Support random order I/O on volmap (volmap 2 phases I/O)

We want to submit I/O by random order (not logical/physical order)
for volmap. Because, for example, we want to flush dleaf with
nearby data pages earlier than ileaf.

But random order has the issue of dirty => clean state on the page.
Because we can't know when random order buffer I/O is done finally.
(while checking last I/O, another I/O can be started.)  This means
we would need some sort of IRQ safe locking for each submit_io and
end_io.

To avoid IRQ safe locking for each buffers, this uses 2 phases I/O.

The 1st phase just submits I/O and increment number of I/O in the delta,
and the 1st phase doesn't touch state of buffer or page at all.
With this, we just update on-disk data without modify in-core state.

After the 1st phase was done, and confirmed all I/O in the delta
was done, we start the 2nd phase to update in-core state.  We know
all state can be clean in the delta.

Because we have stable in-core state in the delta. If frontend
tried to re-dirty same buffer, frontend has to page forking then.
So at the 2nd phase, we walk all buffers, and we set all
buffers/pages pages clean.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Consolidate part of clean_state() and prepare_and_lock_page()

clean_state() cleans page and buffer state, this is same with
bufvec_prepare_and_lock_page(). So this consolidate those.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Optimize tux3_volmap_early_io()

This changes tux3_volmap_early_io() to add multiple contiguous
buffers into a bio, and submit buffers at once.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Flush dleaf with data blocks (Optimization for untar)

dleaf and data blocks are allocated physical address like following
order roughly.

	[dleaf][data][dleaf][data][dleaf][data, data]

Blocks are flushed for each inode, and dleaf blocks belongs to
volmap. I.e. data blocks are flushed first as normal inode, then dleaf
blocks (volmap) are flushed after all normal inodes was flushed.

This means, dleaf blocks bothers to make big I/O request, and become
cause of small many I/O requests.

To optimize this issue, flush dleaf blocks early and with data blocks.

[before (4096 blocksize) without direct extent]
==== untar
real	0m3.823s
user	0m0.440s
sys	0m2.076s
==== sync
real	0m50.195s
user	0m0.000s
sys	0m0.024s

[after (4096 blocksize) without direct extent]
==== untar
real	0m3.442s
user	0m0.388s
sys	0m2.152s
==== sync
real	0m19.245s
user	0m0.004s
sys	0m0.024s

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Flush inode metadata after data blocks

Current allocation order is

	foreach inodes
		1) extent (dtree)
		2) data
		3) inode metadata

So, blocks are allocated like following.

	[dleaf][data][ileaf][dleaf][data][ileaf]

Like dleaf, ileaf bothers to make big I/O request. Because ileaf is
flushed at volmap flush.

To optimize, this flushes ileaf after dleaf/data blocks. I.e.

	foreach inodes
		1) extent (dtree)
		2) data
	foreach inodes
		1) inode metadata

and

	[dleaf][data][dleaf][data][ileaf][ileaf]

This makes big I/O request.

[before (4096)]
==== untar
real	0m3.541s
user	0m0.400s
sys	0m2.108s
==== sync
real	0m15.794s
user	0m0.004s
sys	0m0.024s

[after (4096)]
==== untar
real	0m2.709s
user	0m0.468s
sys	0m2.008s
==== sync
real	0m8.605s
user	0m0.004s
sys	0m0.024s

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Fix "Flush inode metadata after data blocks"

By "Flush inode metadata after data blocks", flush order was
changed. And if inode was marked as dead, it flushes data blocks
without set idata->i_size=0.

If inode is dead, we don't need to flush data blocks. Furthermore,
early flushed dleaf is tried to free by dtree_chop() under I/O. This
become the cause of Oops. (by clearing buffer dirty,
buffer->b_assoc_map become NULL. But, end_io() of early I/O is
assuming ->b_assoc_map is available.)

To fix, this set idata->i_size=0 if inode is dead.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Optimize tar/ls (Flush directory before others)

By locating directories close, "ls" operation can use the device
readahead/cache efficiently.

[before (4096)]
==== tar
tar: Removing leading `/' from member names

real	0m32.809s
user	0m0.380s
sys	0m5.144s

==== ls

real	0m12.927s
user	0m0.056s
sys	0m0.272s

[after (4096)]
==== tar
tar: Removing leading `/' from member names

real	0m14.879s
user	0m0.408s
sys	0m4.988s
==== ls
real	0m1.041s
user	0m0.052s
sys	0m0.268s

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Disable temporarily allocation policy

Current policy decides placement of data blocks based on inum. But
"Optimize tar/ls (Flush directory before others)" patch depends to
place directories close.

So, this temporarily disable current allocation policy.

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