tux3: Use truncate_inode_pages_final() for kernel v3.15

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Push down sync_filesystem() to ->remount() for kernel v3.15

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Add .rename2 stub for kernel v3.15

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Add .map_pages handler for kernel v3.15

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

Add a "writeback" super operation to be called in the form:

        progress = sb->s_op->writeback(sb, &wbc, &pages);

The filesystem is expected to flush some inodes to disk
and return progress of at least 1, or if no inodes are
flushed, return progress of zero. The filesystem should
try to flush at least the number of pages specified in
*pages, or if that is not possible, return approximately
the number of pages not flushed into *pages.

Within the ->writeback callback, the filesystem should
call inode_writeback_done(inode) for each inode flushed
(and therefore set clean) or inode_writeback_touch(inode)
for any inode that will be retained dirty in cache.

Signed-off-by: Daniel Phillips <d.phillips@partner.samsung.com>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Remove writeback hack using new writeback

Instead of re-implementing part of fs/fs-writeback.c, use a proposed
net ->writeback super operation to drive delta writeback. For each
inode that is cleaned, call inode_writeback_done(inode). For each
inode that will be kept dirty in cache, call inode_writeback_touch
so that the inode appears young to fs-writeback and does not trigger
repeated ->writeback flushes.

Signed-off-by: Daniel Phillips <d.phillips@partner.samsung.com>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Allow to copy-on-write the page by ->page_mkwrite() handler

This allows to copy-on-write the page in ->page_mkwrite() handler to
implement page forking.

To allow copy-on-write, caller of do_page_mkwrite() checks if the
vmf->page was changed. Then, if changed, caller of do_page_mkwrite()
updates the PFN of target PTE.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
tux3: Use change of copy-on-write aware ->page_mkwrite()

This removes hacks to do copy-on-write by old ->page_mkwrite().

With this change, tux3_page_mkwrite() doesn't need to play with
refcount of page anymore, and became simpler and straight for page
forking.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
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 ->page_mkwrite() cares about 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() cares about 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>