Revert "Update to latest F2FS"

This reverts commit a4c693c5fd4066f8afd35663f730bde7b2b23194.
Revert "add support for f2fs"

This reverts commit 712c63d2e970f5b577f279284219c4a3bd2dfba0.
Squashed commit of the following:

commit 5f42ce46b77ea1aa334e748f5dab6bc46a9947e7
Author: Jamie Morris <jamiethemorris@gmail.com>
Date:   Wed Jul 23 14:23:47 2014 -0700

    enable f2fs in jamiethemorris_defconfig

commit 187e8fc869af23032da13fd0f6990ff074b09810
Author: invisiblek <dan.pasanen@gmail.com>
Date:   Mon Jul 21 09:30:34 2014 -0500

    dlx: enable f2fs support

    Change-Id: Ia3504e745a7d339112da6c93f772950cb78e20f5

commit 927a03575036b9680867fa6e1bda8d708c06d6fd
Author: Evan McClain <aeroevan@gmail.com>
Date:   Thu Jul 17 21:16:35 2014 -0400

    f2fs: Update to proper 3.4 support

    http://git.kernel.org/cgit/linux/kernel/git/jaegeuk/f2fs.git/log/?h=linux-3.4

    Change-Id: Ica17871e847d4807c7ef24ea77dd4bff5451f5c7

    Conflicts:
    	fs/f2fs/f2fs.h

commit bbbbc09f0a068f7eca57091aaa15ae4cc0ea2f7d
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Sat Jun 28 01:00:41 2014 +0900

    f2fs: check bdi->dirty_exceeded when trying to skip data writes

    If we don't check the current backing device status, balance_dirty_pages can
    fall into infinite pausing routine.

    This can be occurred when a lot of directories make a small number of dirty
    dentry pages including files.

    Reported-by: Brian Chadwick <brianchad@westnet.com.au>
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit 5dd97c079ef16e91ed1715a29998e86c92db0f35
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Mon Jun 30 18:09:55 2014 +0900

    f2fs: do checkpoint for the renamed inode

    If an inode is renamed, it should be registered as file_lost_pino to conduct
    checkpoint at f2fs_sync_file.
    Otherwise, the inode cannot be recovered due to no dent_mark in the following
    scenario.

    Note that, this scenario is from xfstests/322.

    1. create "a"
    2. fsync "a"
    3. rename "a" to "b"
    4. fsync "b"
    5. Sudden power-cut

    After recovery is done, "b" should be seen.
    However, the result shows "a", since the recovery procedure does not enter
    recover_dentry due to no dent_mark.

    The reason is like below.
    - The nid of "a" is checkpointed during #2, f2fs_sync_file.
    - The inode page for "b" produced by #3 is written without dent_mark by
    sync_node_pages.

    So, this patch fixes this bug by assinging file_lost_pino to the "a"'s inode.
    If the pino is lost, f2fs_sync_file conducts checkpoint, and then recovers
    the latest pino and its dentry information for further recovery.

    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit cc95a852ae834fa0f45f5eedc4c9bb6b2183d6fb
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue Jun 24 14:13:13 2014 +0800

    f2fs: release new entry page correctly in error path of f2fs_rename

    This patch correct releasing code of new_page to avoid BUG_ON in error patch of
    f2fs_rename.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit 9c1b493c6aec556b5b016ee11df0662dacc69ae3
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue Jun 24 10:34:00 2014 +0800

    f2fs: fix error path in init_inode_metadata

    If we fail in this path:
    ->init_inode_metadata
      ->make_empty_dir
        ->get_new_data_page
          ->grab_cache_page return -ENOMEM

    We will bug on in error path of init_inode_metadata when call remove_inode_page
    because i_block = 2 (one inode block will be released later & one dentry block).

    We should release the dentry block in init_inode_metadata to avoid this BUG_ON,
    and avoid leak of dentry block resource, because we never have second chance to
    release that block in ->evict_inode as in upper error path we make this inode
    'bad'.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit f0cb1e74319433921561b5b2acd36efb583232eb
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Thu Jun 12 13:23:41 2014 +0800

    f2fs: check lower bound nid value in check_nid_range

    This patch add lower bound verification for nid in check_nid_range, so nids
    reserved like 0, node, meta passed by caller could be checked there.

    And then check_nid_range could be used in f2fs_nfs_get_inode for simplifying
    code.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit 9951e8e65d02072a117f471454325aebc28abf0c
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Wed Jun 11 18:32:23 2014 +0800

    f2fs: remove unused variables in f2fs_sm_info

    Remove unused variables in struct f2fs_sm_info.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit 68a0bb3b4f7d42bd114578b543209e422b808b1a
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Fri Jun 13 13:07:31 2014 +0900

    f2fs: fix not to allocate unnecessary blocks during fallocate

    This patch fixes the fallocate bug like below. (See xfstests/255)

    In fallocate(fd, 0, 20480),
    expand_inode_data processes
    	for (index = pg_start; index <= pg_end; index++) {
    		f2fs_reserve_block();
    		...
    	}

    So, even though fallocate requests 20480, 5 blocks, f2fs allocates 6 blocks
    including pg_end.
    So, this patch adds one condition to avoid block allocation.

    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit b00b9175894b9df459200d90ba1318d48d69216f
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Fri Jun 13 13:05:55 2014 +0900

    f2fs: recover fallocated data and its i_size together

    This patch arranges the f2fs_locks to cover the fallocated data and its i_size.

    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit 71fc2e277143d022a41f1957ca69fed1f758844f
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Fri Jun 13 13:02:11 2014 +0900

    f2fs: fix to report newly allocate region as extent

    Previous get_block in f2fs didn't report the newly allocated region which has
    NEW_ADDR.
    For reader, it should not report, but fiemap needs this.
    So, this patch introduces two get_block sharing core function.

    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit 20295abad74fbc77c487236cb11c73cdc5406067
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Sun Jun 8 04:30:14 2014 +0900

    f2fs: support f2fs_fiemap

    This patch links f2fs_fiemap with generic function with get_block.

    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit 1fa0af75609b4e1fd9aa57f30c825450ccdb6882
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Sat Jun 7 03:05:03 2014 +0900

    f2fs: avoid not to call remove_dirty_inode

    There is an errorneous case during the recovery like below.

    In recovery_dentry,
     1) dir = f2fs_iget();
     2) mark the dir with FI_DELAY_IPUT
     3) goto unmap_out

    After the end of recovery routine, there is no dirty dentries so the dir cannot
    be released by iput in remove_dirty_dir_inode.

    This patch fixes such the bug case by handling the iget and iput in the
    recovery_dentry procedure.

    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit b7c0fac8b3b161a43ee0c90c52e5dbed8684d536
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Fri Jun 6 02:12:59 2014 +0900

    f2fs: recover fallocated space

    If a fallocated file is fsynced, we should recover the i_size after sudden
    power cut.

    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit 56cf935a893bc605d8ae98a4c8389150379528a9
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Wed Jun 4 00:39:42 2014 +0900

    f2fs: fix to recover data written by dio

    If data are overwritten through dio, previous f2fs doesn't remain the fsync mark
    due to no additional node writes.

    Note that this patch should resolve the xfstests:311.

    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit 9e21161d627a72049403d9c781da40a17cf1c9ce
Author: Changman Lee <cm224.lee@samsung.com>
Date:   Mon May 12 12:27:43 2014 +0900

    f2fs: large volume support

    f2fs's cp has one page which consists of struct f2fs_checkpoint and
    version bitmap of sit and nat. To support lots of segments, we need more
    blocks for sit bitmap. So let's arrange sit bitmap as following:
    +-----------------+------------+
    | f2fs_checkpoint | sit bitmap |
    | + nat bitmap    |            |
    +-----------------+------------+
    0                 4k        N blocks

    Signed-off-by: Changman Lee <cm224.lee@samsung.com>
    [Jaegeuk Kim: simple code change for readability]
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit c42e0591164239912f465635ff8e0182c12201d6
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue May 27 08:41:07 2014 +0800

    f2fs: avoid crash when trace f2fs_submit_page_mbio event in ra_sum_pages

    Previously we allocate pages with no mapping in ra_sum_pages(), so we may
    encounter a crash in event trace of f2fs_submit_page_mbio where we access
    mapping data of the page.

    We'd better allocate pages in bd_inode mapping and invalidate these pages after
    we restore data from pages. It could avoid crash in above scenario.

    Changes from V1
     o remove redundant code in ra_sum_pages() suggested by Jaegeuk Kim.

    Call Trace:
     [<f1031630>] ? ftrace_raw_event_f2fs_write_checkpoint+0x80/0x80 [f2fs]
     [<f10377bb>] f2fs_submit_page_mbio+0x1cb/0x200 [f2fs]
     [<f103c5da>] restore_node_summary+0x13a/0x280 [f2fs]
     [<f103e22d>] build_curseg+0x2bd/0x620 [f2fs]
     [<f104043b>] build_segment_manager+0x1cb/0x920 [f2fs]
     [<f1032c85>] f2fs_fill_super+0x535/0x8e0 [f2fs]
     [<c115b66a>] mount_bdev+0x16a/0x1a0
     [<f102f63f>] f2fs_mount+0x1f/0x30 [f2fs]
     [<c115c096>] mount_fs+0x36/0x170
     [<c1173635>] vfs_kern_mount+0x55/0xe0
     [<c1175388>] do_mount+0x1e8/0x900
     [<c1175d72>] SyS_mount+0x82/0xc0
     [<c16059cc>] sysenter_do_call+0x12/0x22

    Suggested-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit b814e0fe335f24caa41e09ed001e8dce2f204f82
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Wed May 28 08:56:09 2014 +0800

    f2fs: avoid overflow when large directory feathure is enabled

    When large directory feathure is enable, We have one case which could cause
    overflow in dir_buckets() as following:
    special case: level + dir_level >= 32 and level < MAX_DIR_HASH_DEPTH / 2.

    Here we define MAX_DIR_BUCKETS to limit the return value when the condition
    could trigger potential overflow.

    Changes from V1
     o modify description of calculation in f2fs.txt suggested by Changman Lee.

    Suggested-by: Changman Lee <cm224.lee@samsung.com>
    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit cc76644f047b0276aea1f7fb106301766f5d2750
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Sun Jun 1 23:24:30 2014 +0900

    f2fs: fix recursive lock by f2fs_setxattr

    This patch should resolve the following recursive lock.

    [<ffffffff8135a9c3>] call_rwsem_down_write_failed+0x13/0x20
    [<ffffffffa01749dc>] f2fs_setxattr+0x5c/0xa0 [f2fs]
    [<ffffffffa0174c99>] __f2fs_set_acl+0x1b9/0x340 [f2fs]
    [<ffffffffa017515a>] f2fs_init_acl+0x4a/0xcb [f2fs]
    [<ffffffffa0159abe>] __f2fs_add_link+0x26e/0x780 [f2fs]
    [<ffffffffa015d4d8>] f2fs_mkdir+0xb8/0x150 [f2fs]
    [<ffffffff811cebd7>] vfs_mkdir+0xb7/0x160
    [<ffffffff811cf89b>] SyS_mkdir+0xab/0xe0
    [<ffffffff817244bf>] tracesys+0xe1/0xe6
    [<ffffffffffffffff>] 0xffffffffffffffff

    The call path indicates:
    - f2fs_add_link
       : down_write(&fi->i_sem);

     - init_inode_metadata
       - f2fs_init_acl
         - __f2fs_set_acl
           - f2fs_setxattr
             : down_write(&fi->i_sem);

    Here we should not call f2fs_setxattr, but __f2fs_setxattr.
    But __f2fs_setxattr is a static function in xattr.c, so that I found the other
    generic approach to use f2fs_setxattr.

    In f2fs_setxattr, the page pointer is only given from init_inode_metadata.
    So, this patch adds this condition to avoid this in f2fs_setxattr.

    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit 35fd2f984a5ae64a7c2409fce62a764246d224a9
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue May 6 16:53:08 2014 +0800

    f2fs: add a tracepoint for f2fs_read_data_page

    This patch adds a tracepoint for f2fs_read_data_page to trace when page is
    readed by user.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 200128153ee675d319921dbecf8ad87d448a0c57
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue May 6 16:51:24 2014 +0800

    f2fs: add a tracepoint for f2fs_write_{meta,node,data}_pages

    This patch adds a tracepoint for f2fs_write_{meta,node,data}_pages to trace when
    pages are fsyncing/flushing.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit e78455512ea48c777055f4fe35cbf4baf091ed78
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue May 6 16:48:26 2014 +0800

    f2fs: add a tracepoint for f2fs_write_{meta,node,data}_page

    This patch adds a tracepoint for f2fs_write_{meta,node,data}_page to trace when
    page is writting out.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 509af90e0afcbc2b844214a8cfc5d8af7e750861
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue May 6 16:47:23 2014 +0800

    f2fs: add a tracepoint for f2fs_write_end

    This patch adds a tracepoint for f2fs_write_end to trace write op of user.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 48687c90f4db51de9e31c93ab842013ebfa83635
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue May 6 16:46:04 2014 +0800

    f2fs: add a tracepoint for f2fs_write_begin

    This patch adds a tracepoint for f2fs_write_begin to trace write op of user.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 74ba5bb82fcaf4560e1df1b15835f2b577b114e1
Author: Zhang Zhen <zhenzhang.zhang@huawei.com>
Date:   Sun May 4 16:37:06 2014 +0800

    f2fs: fix checkpatch warning

    fix the following checkpatch warning:
    WARNING: do {} while (0) macros should not be semicolon terminated

    Signed-off-by: Zhang Zhen <zhenzhang.zhang@huawei.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 7b4e3ba8b705995bbc072cc8dcec6b79975d15b0
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Apr 30 09:22:45 2014 +0900

    f2fs: decrease the lock granularity during write_begin

    This patch reduces the lock granularity during write_begin.
    When the system is under memory pressure, it would be better to reduce
    the locking time for the data pages.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit d734eaf7083d0d238f4b0efebf732b46effe354e
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Apr 30 09:18:53 2014 +0900

    f2fs: no need to wait on page writebck to meta pages

    This patch removes grab_cache_page_write_begin for meta pages.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit a01e388618847f8564991c6b358d567c65bbe0bf
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Apr 29 17:35:10 2014 +0900

    f2fs: avoid grab_cache_page_write_begin for data pages

    We don't need to wait on page writeback for these cases.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit bececcb6dfb5959c9b9e148f4dadc94202ee5af7
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Apr 29 17:28:32 2014 +0900

    f2fs: split grab_cache_page and wait_on_page_writeback for node pages

    This patch splits grab_cache_page_write_begin into grab_cache_page and
    wait_on_page_writeback for node pages.

    This patch intends to enhance the latency to get node pages by alleviating
    unnecessary wait_on_page_writeback.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 98fd7654cd5320fc7b42bbcd360bf03120f43ce7
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue Apr 29 09:03:03 2014 +0800

    f2fs: fix to truncate inline data in inode page when setattr

    Previous we do not truncate inline data in inode page when setattr, so following
    case could still read the inline data which has already truncated:

    1.write inline data
    2.ftruncate size to 0
    3.ftruncate size to max inline data size
    4.read from offset 0

    This patch introduces truncate_inline_data() to fix this problem.

    change log from v1:
     o fix a bug and do not truncate first page data after truncate inline data.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit d1ce8736f7f34bfb3cf443638d05a476f37f8a19
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Mon Apr 28 17:59:43 2014 +0800

    f2fs: readahead multi pages of directory for performance

    We have no so such readahead mechanism in ->iterate() path as the one in
    ->read() path, it cause low performance when we read large directory.
    This patch add readahead in f2fs_readdir() for better performance.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    Conflicts:
    	fs/f2fs/dir.c

    Change-Id: I2c3c4e204a32dc6486f1a04551f7db619a9e63e8

commit 60ae5f9f8e18f8c5e1ed98da960f736627af690e
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Mon Apr 28 17:58:34 2014 +0800

    f2fs: set errno when f2fs_iget failed in recover_dentry

    We should set the error number correctly when we fail in recover_dentry(), so
    the recover flow could stop for the reason as error number shows instead of
    continuing.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 76c9fc314b3eed1c8a622fc0260aa306335a64ab
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Sat Apr 26 19:59:52 2014 +0800

    f2fs: introduce help macro ADDRS_PER_PAGE()

    Introduce help macro ADDRS_PER_PAGE() to get the number of address pointers in
    direct node or inode.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 5299397db61d85bc5241634c05092f238eb3f4f8
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Thu Apr 24 09:49:52 2014 +0900

    f2fs: submit bio at the reclaim path

    If f2fs_write_data_page is called through the reclaim path, we should submit
    the bio right away.

    This patch resolves the following issue that Marc Dietrich reported.
    "It took me a while to bisect a problem which causes my ARM (tegra2) netbook to
    frequently stall for 5-10 seconds when I enable EXA acceleration (opentegra
    experimental ddx)."
    And this patch fixes that.

    Reported-by: Marc Dietrich <marvin24@gmx.de>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 66abb6bd3eb89f45244bcddad0093fe8d606a8f0
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Apr 23 12:28:18 2014 +0900

    f2fs: return errors right after checking them

    This patch adds two error conditions early in the setxattr operations.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 1f1ad063370d1b85f91968963f9ad2803d3b912d
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Apr 23 12:23:14 2014 +0900

    f2fs: pass flags field to setxattr functions

    This patch passes the "flags" field to the low level setxattr functions
    to use XATTR_REPLACE in the following patches.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 97c80d200aaf9c8679f88b551f1652f79be57725
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Apr 23 12:17:25 2014 +0900

    f2fs: clean up long variable names

    This patch includes simple clean-ups to reduce unnecessary long variable names.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 7bc6d896f55b5055e3513c6641a69c2f3ad48bc6
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue Apr 22 13:34:01 2014 +0800

    f2fs: handle inline data independently in f2fs_bmap

    We'd better handle inline data case independently in f2fs_bmap().
    It can reduce our handling time in f2fs_bmap().

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 587872fd6b75af459f20d0d99ec290363eb5ce45
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Apr 16 10:47:06 2014 +0900

    f2fs: adjust free mem size to flush dentry blocks

    If so many dirty dentry blocks are cached, not reached to the flush condition,
    we should fall into livelock in balance_dirty_pages.
    So, let's consider the mem size for the condition.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit b6aa5cb1ca97985fde164d256fa7f931dff81c44
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Thu Apr 17 10:51:05 2014 +0800

    f2fs: introduce raw_nat_from_node_info() to simplfy codes

    This patch introduce raw_nat_from_node_info() to simplfy some codes, and also
    use exist function node_info_from_raw_nat() to do the same job.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 6fafdc6ad5290deb3bca7be7ece0dc634ac49488
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Fri Apr 18 15:21:04 2014 +0900

    f2fs: avoid BUG_ON when mouting corrupted image having garbage blocks

    If the disk has some garbage blocks, F2FS is able to face with BUG_ON when
    recovering direct node blocks.
    This patch detects the error case and avoids that prior to reaching BUG_ON.

    Alexey Khoroshilov addressed the potential security issues as follows.
    "An ability to trigger a BUG_ON assert by mounting a crafted image is
    usually considered as a local denial of service [1-3]. As far as I
    understand, the reason is that some kernel data may become inconsistent
    that can lead to further problems.

    [1] http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3353
    [2] http://www.openwall.com/lists/oss-security/2011/06/24/4
    [3] http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-2928
    etc."

    Reported-by: Andrey Tsyvarev <tsyvarev@ispras.ru>
    Cc: Alexey Khoroshilov <khoroshilov@ispras.ru>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 80eb96d805811892b735d514b6f4131ade2ab9a9
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Fri Apr 18 11:14:37 2014 +0900

    f2fs: add available_nids to fix handling max_nid correctly

    This patch introduces available_nids for alloc_nids() and fixes max_nid for
    build_free_nids() and scan_nat_pages().

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Reviewed-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 9e030a7bccd98c8973d6547a4f773978b954c322
Author: Fabian Frederick <fabf@skynet.be>
Date:   Thu Apr 17 17:51:06 2014 +0200

    f2fs: add static to get_max_meta_blks

    inline get_max_meta_blks is only used in checkpoint.c
    Use standard static inline format.

    Cc: Jaegeuk Kim <jaegeuk.kim@samsung.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Fabian Frederick <fabf@skynet.be>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit dbb6614fee387323978ac2b287779cb94909a065
Author: Zhang Zhen <zhenzhang.zhang@huawei.com>
Date:   Tue Apr 15 14:19:38 2014 +0800

    f2fs: atomically set inode->i_flags in f2fs_set_inode_flags()

    Use set_mask_bits() to atomically set i_flags instead of clearing out the
    S_IMMUTABLE, S_APPEND, etc. flags and then setting them from the
    FS_IMMUTABLE_FL, FS_APPEND_FL, etc. flags, since this opens up a race
    where an immutable file has the immutable flag cleared for a brief
    window of time.

    Signed-off-by: Zhang Zhen <zhenzhang.zhang@huawei.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 03d412ad5d02b11c7b7572850963f3b2d2e33207
Author: Jingoo Han <jg1.han@samsung.com>
Date:   Tue Apr 15 17:51:05 2014 +0900

    f2fs: make recover_inline_xattr() static

    Make recover_inline_xattr() static, because this function is
    used only in this file.

    Signed-off-by: Jingoo Han <jg1.han@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit ad6f942bf2dcabe3a3b137169ed114d0c01d6e2f
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Apr 15 11:19:28 2014 +0900

    f2fs: remove costly dirty_dir_inode operations

    This patch removes list opeations in handling dirty dir inodes.
    Previously, F2FS traverses whole the list of dirty dir inodes to check whether
    there is an existing inode or not, resulting in heavy CPU overheads.

    So this patch removes such the traverse operations by adding FI_DIRTY_DIR to
    indicate the inode lies on the list or not.
    Through this simple flag, we can remove redundant operations gracefully.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 47c12a51aba536da74ab2b77a56c0042a0f33cb6
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Apr 16 14:22:50 2014 +0900

    f2fs: fix to unlock f2fs_lock at the omitted error case

    If it occurs an error, we should call f2fs_unlock_op.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit a8c1abf7282cb85edb67354bd7d030a42f2fd0b6
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Apr 15 16:04:15 2014 +0900

    f2fs: call redirty_page_for_writepage

    This patch replace some general codes with redirty_page_for_writepage, which
    can be enabled after consideration on additional procedure like counting dirty
    pages appropriately.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 5e2c783b109baf251dae20528a9f19c9da999288
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Apr 15 13:57:55 2014 +0900

    f2fs: avoid to conduct roll-forward due to the remained garbage blocks

    The f2fs always scans the next chain of direct node blocks.
    But some garbage blocks are able to be remained due to no discard support or
    SSR triggers.
    This occasionally wreaks recovering wrong inodes that were used or BUG_ONs
    due to reallocating node ids as follows.

    When mount this f2fs image:
    http://linuxtesting.org/downloads/f2fs_fault_image.zip
    BUG_ON is triggered in f2fs driver (messages below are generated on
    kernel 3.13.2; for other kernels output is similar):

    kernel BUG at fs/f2fs/node.c:215!
     Call Trace:
     [<ffffffffa032ebad>] recover_inode_page+0x1fd/0x3e0 [f2fs]
     [<ffffffff811446e7>] ? __lock_page+0x67/0x70
     [<ffffffff81089990>] ? autoremove_wake_function+0x50/0x50
     [<ffffffffa0337788>] recover_fsync_data+0x1398/0x15d0 [f2fs]
     [<ffffffff812b9e5c>] ? selinux_d_instantiate+0x1c/0x20
     [<ffffffff811cb20b>] ? d_instantiate+0x5b/0x80
     [<ffffffffa0321044>] f2fs_fill_super+0xb04/0xbf0 [f2fs]
     [<ffffffff811b861e>] ? mount_bdev+0x7e/0x210
     [<ffffffff811b8769>] mount_bdev+0x1c9/0x210
     [<ffffffffa0320540>] ? validate_superblock+0x210/0x210 [f2fs]
     [<ffffffffa031cf8d>] f2fs_mount+0x1d/0x30 [f2fs]
     [<ffffffff811b9497>] mount_fs+0x47/0x1c0
     [<ffffffff81166e00>] ? __alloc_percpu+0x10/0x20
     [<ffffffff811d4032>] vfs_kern_mount+0x72/0x110
     [<ffffffff811d6763>] do_mount+0x493/0x910
     [<ffffffff811615cb>] ? strndup_user+0x5b/0x80
     [<ffffffff811d6c70>] SyS_mount+0x90/0xe0
     [<ffffffff8166f8d9>] system_call_fastpath+0x16/0x1b

    Found by Linux File System Verification project (linuxtesting.org).

    Reported-by: Andrey Tsyvarev <tsyvarev@ispras.ru>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 2299ffc883dc2256cd23df35fe59e4d64d5b0d5a
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Mon Apr 7 11:18:34 2014 +0800

    f2fs: fix wrong statistics of inline data

    If we remove a file that has inline data after mount, our statistics turns to
    inaccurate.

    cat /sys/kernel/debug/f2fs/status
      - Inline_data Inode: 4294967295

    Let's add stat_inc_inline_inode() to stat inline info of the file when lookup.

    Change log from v1:
     o stat in f2fs_lookup() instead of in do_read_inode() for excluding wrong stat.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit f6ca5ddd81ffbaeda3fe21dbed4ec10791ba6d4f
Author: Huajun Li <huajun.li@intel.com>
Date:   Sun Nov 10 23:13:21 2013 +0800

    f2fs: update f2fs Documentation

    This patch describes the inline_data support in f2fs document.

    Signed-off-by: Huajun Li <huajun.li@intel.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 71c39512e85f46d0704fcc4b3bc185f30b07792b
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Sat Mar 29 15:30:40 2014 +0800

    f2fs: fix error path when fail to read inline data

    We should unlock page in ->readpage() path and also should unlock & release page
    in error path of ->write_begin() to avoid deadlock or memory leak.
    So let's add release code to fix the problem when we fail to read inline data.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 61e0f29ac4fad1d64043829bed7d08d29b81f6bb
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Sat Mar 29 11:33:17 2014 +0800

    f2fs: use list_for_each_entry{_safe} for simplyfying code

    This patch use list_for_each_entry{_safe} instead of list_for_each{_safe} for
    simplfying code.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit f3139e1e6133856225e361f2880c8062d08335c7
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Wed Apr 2 08:55:00 2014 +0800

    f2fs: avoid free slab cache under spinlock

    Move kmem_cache_free out of spinlock protection region for better performance.

    Change log from v1:
     o remove spinlock protection for kmem_cache_free in destroy_node_manager
    suggested by Jaegeuk Kim.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit f51517bfb550ad54e51c23c5a07c09034fdc7fc4
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Sat Mar 22 14:59:45 2014 +0800

    f2fs: avoid unneeded lookup when xattr name length is too long

    In f2fs_setxattr we have limit this attribute name length, so we should also
    check it in f2fs_getxattr to avoid useless lookup caused by invalid name length.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 9a36222c77bbfa274fd3e9ccb3b1e99195722a61
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Apr 1 17:38:26 2014 +0900

    f2fs: return -EIO when node id is not matched

    During the cleaing of node segments, F2FS can get errored node blocks due to
    data race between node page lock and its valid bitmap operations.
    In that case, it needs to return an error to skip such the obsolete block copy.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 8bf9e2a5eddcdb6912a1ed726f7c4314c6c0c154
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Thu Mar 20 22:21:08 2014 +0900

    f2fs: avoid RECLAIM_FS-ON-W warning

    This patch should resolve the following possible bug.

    RECLAIM_FS-ON-W at:
     mark_held_locks+0xb9/0x140
     lockdep_trace_alloc+0x85/0xf0
     __kmalloc+0x53/0x1d0
     read_all_xattrs+0x3d1/0x3f0 [f2fs]
     f2fs_getxattr+0x4f/0x100 [f2fs]
     f2fs_get_acl+0x4c/0x290 [f2fs]
     get_acl+0x4f/0x80
     posix_acl_create+0x72/0x180
     f2fs_init_acl+0x29/0xcc [f2fs]
     __f2fs_add_link+0x259/0x710 [f2fs]
     f2fs_create+0xad/0x1c0 [f2fs]
     vfs_create+0xed/0x150
     do_last+0xd36/0xed0
     path_openat+0xc5/0x680
     do_filp_open+0x43/0xa0
     do_sys_open+0x13c/0x230
     SyS_creat+0x1e/0x20
     system_call_fastpath+0x16/0x1b

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit b4da852731c4b25b94f48ba28e4ccf0a07b421f0
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Thu Mar 20 21:52:53 2014 +0900

    f2fs: skip unnecessary node writes during fsync

    If multiple redundant fsync calls are triggered, we don't need to write its
    node pages with fsync mark continuously.

    So, this patch adds FI_NEED_FSYNC to track whether the latest node block is
    written with the fsync mark or not.
    If the mark was set, a new fsync doesn't need to write a node block.
    Otherwise, we should do a new node block with the mark for roll-forward
    recovery.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit fb1eb9bd7b1960b626223bd33515083eed1339c6
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Thu Mar 20 19:10:08 2014 +0900

    f2fs: introduce fi->i_sem to protect fi's info

    This patch introduces fi->i_sem to protect fi's info that includes xattr_ver,
    pino, i_nlink.
    This enables to remove i_mutex during f2fs_sync_file, resulting in performance
    improvement when a number of fsync calls are triggered from many concurrent
    threads.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit f34cc7f9152bbccac4f9c114340993608729b711
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Mar 19 14:17:21 2014 +0900

    f2fs: change reclaim rate in percentage

    It is more reasonable to determine the reclaiming rate of prefree segments
    according to the volume size, which is set to 5% by default.
    For example, if the volume is 128GB, the prefree segments are reclaimed
    when the number reaches to 6.4GB.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 69c6d61d6401a50206d34f26353597aefce76cba
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Mar 19 13:45:52 2014 +0900

    f2fs: remove unnecessary threshold

    The NM_WOUT_THRESHOLD is now obsolete since f2fs starts to control on a basis
    of the memory footprint.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit a0cac12b9f09c8fbe0c1beda2876d7607c1e01cb
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Mar 19 13:31:37 2014 +0900

    f2fs: throttle the memory footprint with a sysfs entry

    This patch introduces ram_thresh, a sysfs entry, which controls the memory
    footprint used by the free nid list and the nat cache.

    Previously, the free nid list was controlled by MAX_FREE_NIDS, while the nat
    cache was managed by NM_WOUT_THRESHOLD.
    However, this approach cannot be applied dynamically according to the system.

    So, this patch adds ram_thresh that users can specify the threshold, which is
    in order of 1 / 1024.
    For example, if the total ram size is 4GB and the value is set to 10 by default,
    f2fs tries to control the number of free nids and nat caches not to consume over
    10 * (4GB / 1024) = 10MB.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 3844b3ffb457d34cd54da49b271d61ca017a8bed
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Mar 19 10:43:59 2014 +0900

    f2fs: avoid to drop nat entries due to the negative nr_shrink

    The try_to_free_nats should not receive the negative nr_shrink.
    Otherwise, it can drop all the nat entries by the while loop.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 85eae41a32e82e3177a21bdb8c720b9673ca5dad
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Mar 18 13:29:07 2014 +0900

    f2fs: call f2fs_wait_on_page_writeback instead of native function

    If a page is on writeback, f2fs can face with deadlock due to under writepages.
    This is caused by merging IOs inside f2fs, so if it comes to detect, let's throw
    merged IOs, which is implemented by f2fs_wait_on_page_writeback.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 5ee375404ba25ac58d562e9b131324cbcb17856c
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Mar 18 13:47:11 2014 +0900

    f2fs: introduce nr_pages_to_write for segment alignment

    This patch introduces nr_pages_to_write to align page writes to the segment
    or other operational unit size, which can be tuned according to the system
    environment.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 0428e9cd69c6ef06d42e80bac9ffa99a9e9051a9
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Mar 18 13:43:05 2014 +0900

    f2fs: increase pages_skipped when skipping writepages

    This patch increases pages_skipped when skipping writepages.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit c043bdf1550ba5b672bde7048ce62d085eeeaba2
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Mar 18 12:40:49 2014 +0900

    f2fs: avoid small data writes by skipping writepages

    This patch introduces nr_pages_to_skip(sbi, type) to determine writepages can
    be skipped.
    The dentry, node, and meta pages can be conrolled by F2FS without breaking the
    FS consistency.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit d6ccc8863921787b204881ed5a3b65c2cd913613
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Mar 18 12:33:06 2014 +0900

    f2fs: introduce get_dirty_dents for readability

    The get_dirty_dents gives us the number of dirty dentry pages.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 8b839811e9d15d419d52637c9f1beaa1eef4d2c6
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue Mar 18 09:07:59 2014 +0800

    f2fs: fix incorrect parsing with option string

    Previously 'background_gc={on***,off***}' is being parsed as correct option,
    with this patch we cloud fix the trivial bug in mount process.

    Change log from v1:
     o need to check length of parameter suggested by Jaegeuk Kim.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit d52ae64f3ec4949df6affd2c6a0dbb701b93d6e4
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Mon Mar 17 16:36:24 2014 +0800

    f2fs: avoid to return incorrect errno of read_normal_summaries

    We should return error number of read_normal_summaries instead of -EINVAL when
    read_normal_summaries failed.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 8fc36a1c4ce5ece9cbc58763100c46557d98ec9f
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Mon Mar 17 16:35:06 2014 +0800

    f2fs: introduce f2fs_has_xattr_block for better readability

    This patch introduces a help function f2fs_has_xattr_block for better
    readability.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit d1f03ab5e510cd9e871e22a81d6ebfc7acc53eed
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Mon Mar 17 10:31:06 2014 +0800

    f2fs: print type for each segment in segment_info's show

    The original segment_info's show looks out-of-format:
    cat /proc/fs/f2fs/loop0/segment_info
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 512
    512 512 512 512 512 512 512 0 0 512
    348 0 263 0 0 512 0 0 512 512
    512 512 0 512 512 512 512 512 512 512
    512 512 511 328 512 512 512 512 512 512
    512 512 512 512 512 512 512 0 0 175

    Let's fix this and show type for each segment.
    cat /proc/fs/f2fs/loop0/segment_info
    format: segment_type|valid_blocks
    segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)
    0    2|0   1|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0
    10   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0
    20   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0
    30   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0
    40   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0
    50   3|0   3|0   3|0   3|0   3|0   3|0   3|0   0|0   3|0   3|0
    60   3|0   3|0   3|0   3|0   3|0   3|0   3|0   3|0   3|0   3|512
    70   3|512 3|512 3|512 3|512 3|512 3|512 3|512 3|0   3|0   3|512
    80   3|0   3|0   3|0   3|0   3|0   3|512 3|0   3|0   3|512 3|512
    90   3|512 0|512 3|274 0|512 0|512 0|512 0|512 0|512 0|512 3|512
    100  3|512 0|512 3|511 0|328 3|512 0|512 0|512 3|512 0|512 0|512
    110  0|512 0|512 0|512 0|512 0|512 0|512 0|512 5|0   4|0   3|512

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit c78959c5f03dfa060b7a010ad7b18a279bf1d9ce
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Wed Mar 12 17:08:36 2014 +0800

    f2fs: check upper bound of ino value in f2fs_nfs_get_inode

    Upper bound checking of ino should be added to f2fs_nfs_get_inode, so unneeded
    process before do_read_inode in f2fs_iget could be avoided when ino is invalid.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 4d21c586ff3120541ac7e39d983bb76fce02dd88
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Wed Mar 12 15:59:03 2014 +0800

    f2fs: introduce f2fs_has_inline_xattr for better readability

    This patch introduces a help function f2fs_has_inline_xattr for better
    readability.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit f2ed66ce8724faeda4f8f7fe9f3e41f848859983
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue Mar 11 13:37:38 2014 +0800

    f2fs: recover inline xattr data in roll-forward process

    Previously we do not recover inline xattr data of inode after power-cut, so
    inline xattr data may be lost.
    We should recover the data during the roll-forward process.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 309c2519eefbd56b95cd06d1e2b961d484881ef1
Author: Gu Zheng <guz.fnst@cn.fujitsu.com>
Date:   Fri Mar 7 18:43:36 2014 +0800

    f2fs: optimize restore_node_summary slightly

    Previously, we ra_sum_pages to pre-read contiguous pages as more
    as possible, and if we fail to alloc more pages, an ENOMEM error
    will be reported upstream, even though we have alloced some pages
    yet. In fact, we can use the available pages to do the job partly,
    and continue the rest in the following circle. Only reporting ENOMEM
    upstream if we really can not alloc any available page.

    And another fix is ignoring dealing with the following pages if an
    EIO occurs when reading page from page_list.

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Reviewed-by: Chao Yu <chao2.yu@samsung.com>
    [Jaegeuk Kim: modify the flow for better neat code]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 6e1e28d5e35ce76af60344ca6e941cd2f977d845
Author: Gu Zheng <guz.fnst@cn.fujitsu.com>
Date:   Fri Mar 7 18:43:33 2014 +0800

    f2fs: format segment_info's show for better legibility

    The original segment_info's show is a bit out-of-format:

    [root@guz Demoes]# cat /proc/fs/f2fs/loop0/segment_info
    0 0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    ......
    0 0 0 0 0 0 0 0 0 0
    0 0 1 0 0 1 [root@guz Demoes]#

    so we fix it here for better legibility.
    [root@guz Demoes]# cat /proc/fs/f2fs/loop0/segment_info
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    ......
    0 0 0 0 0 0 0 0 0 0
    0 0 1 0 0 1
    [root@guz Demoes]#

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 85facf9924bdf8ae3950f2bf43b69a1bd69e421b
Author: Gu Zheng <guz.fnst@cn.fujitsu.com>
Date:   Fri Mar 7 18:43:28 2014 +0800

    f2fs: remove the unused ctor argument of f2fs_kmem_cache_create()

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 88e487de6eeabf395e09106e1aec6603007e3a25
Author: Gu Zheng <guz.fnst@cn.fujitsu.com>
Date:   Fri Mar 7 18:43:24 2014 +0800

    f2fs: update start nid only once each circle

    Integrated a couple of minor changes for better readability suggested by
    Chao Yu.

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Reviewed-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 8aa32d9b4364337b3a7ed0e6553db0284f312aaa
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Mar 5 10:48:25 2014 +0900

    f2fs: fix wrong kernel coding style

    This patch includes a simple fix to adjust coding style.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 9ff16ac3b88b67e6fd4fcc7586b4633d30ad5301
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Mon Mar 3 11:28:40 2014 +0900

    f2fs: fix to write node pages with WRITE_SYNC

    This patch fixes performance regression of dbench reported by
    Alex <hbx7d@yandex.com>.

    This issue was revealed by Phoronix tests results:
    http://www.phoronix.com/scan.php?page=article&item=linux_314_ssdfs&num=2

    It turns out that we need to assign WRITE_SYNC to the node writes, if
    fsync is triggered.

    The performance numbers are like below, which is measured by Alex.
    1. 355MB/s       ext4
    2. 225MB/s       f2fs : WRITE for node writes
    3. 525MB/s       f2fs : WRITE_SYNC for node writes

    Reported-And-Tested-by: Alex <hbx7d@yandex.com>.
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 12ae4c45c275aac0db7de88a6977844bc002db1c
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Fri Feb 28 10:12:05 2014 +0800

    f2fs: fix dirty page accounting when redirty

    We should de-account dirty counters for page when redirty in ->writepage().

    Wu Fengguang described in 'commit 971767caf632190f77a40b4011c19948232eed75':
    "writeback: fix dirtied pages accounting on redirty
    De-account the accumulative dirty counters on page redirty.

    Page redirties (very common in ext4) will introduce mismatch between
    counters (a) and (b)

    a) NR_DIRTIED, BDI_DIRTIED, tsk->nr_dirtied
    b) NR_WRITTEN, BDI_WRITTEN

    This will introduce systematic errors in balanced_rate and result in
    dirty page position errors (ie. the dirty pages are no longer balanced
    around the global/bdi setpoints)."

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit b1da43d314ecef4636cbcb3a01516d9614bb3164
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Thu Feb 27 19:52:21 2014 +0800

    f2fs: use existing macro to clean up some codes

    This patch use existing macro F2FS_INODE/NEXT_FREE_BLKADDR to clean up some
    codes.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 87359d5bacb0ff1a6cfde3e008b8e042d181d94b
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Thu Feb 27 19:12:24 2014 +0800

    f2fs: readahead contiguous SSA blocks for f2fs_gc

    If there are multi segments in one section, we will read those SSA blocks which
    have contiguous address one by one in f2fs_gc. It may lost performance, let's
    read ahead SSA blocks by merge multi read request.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 686be8847d4ca4960ab1f63ef8f96910cf0cf6f5
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Thu Feb 27 20:09:05 2014 +0900

    f2fs: add an sysfs entry to control the directory level

    This patch adds an sysfs entry to control dir_level used by the large directory.

    The description of this entry is:

     dir_level                    This parameter controls the directory level to
    			      support large directory. If a directory has a
    			      number of files, it can reduce the file lookup
    			      latency by increasing this dir_level value.
    			      Otherwise, it needs to decrease this value to
    			      reduce the space overhead. The default value is 0.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 73bf71c9b2fb326c4491e7a8604921d62add7b69
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Thu Jan 9 21:00:06 2014 +0900

    f2fs: update documents and a MAINTAINERS entry

    This patch adds missing some description of sysfs entries in
     - Documentation/ABI/testing/sysfs-fs-f2fs
     - Documentation/filesystems/f2fs.txt.

    And it adds a maintained document entry of F2FS in MAINTAINERS.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 11a0a83e75cb88535fff76e08a6bf9617861238d
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Thu Feb 27 18:20:00 2014 +0900

    f2fs: introduce large directory support

    This patch introduces an i_dir_level field to support large directory.

    Previously, f2fs maintains multi-level hash tables to find a dentry quickly
    from a bunch of chiild dentries in a directory, and the hash tables consist of
    the following tree structure as below.

    In Documentation/filesystems/f2fs.txt,

    ----------------------
    A : bucket
    B : block
    N : MAX_DIR_HASH_DEPTH
    ----------------------

    level #0   | A(2B)
               |
    level #1   | A(2B) - A(2B)
               |
    level #2   | A(2B) - A(2B) - A(2B) - A(2B)
         .     |   .       .       .       .
    level #N/2 | A(2B) - A(2B) - A(2B) - A(2B) - A(2B) - ... - A(2B)
         .     |   .       .       .       .
    level #N   | A(4B) - A(4B) - A(4B) - A(4B) - A(4B) - ... - A(4B)

    But, if we can guess that a directory will handle a number of child files,
    we don't need to traverse the tree from level #0 to #N all the time.
    Since the lower level tables contain relatively small number of dentries,
    the miss ratio of the target dentry is likely to be high.

    In order to avoid that, we can configure the hash tables sparsely from level #0
    like this.

    level #0   | A(2B) - A(2B) - A(2B) - A(2B)

    level #1   | A(2B) - A(2B) - A(2B) - A(2B) - A(2B) - ... - A(2B)
         .     |   .       .       .       .
    level #N/2 | A(2B) - A(2B) - A(2B) - A(2B) - A(2B) - ... - A(2B)
         .     |   .       .       .       .
    level #N   | A(4B) - A(4B) - A(4B) - A(4B) - A(4B) - ... - A(4B)

    With this structure, we can skip the ineffective tree searches in lower level
    hash tables.

    This patch adds just a facility for this by introducing i_dir_level in
    f2fs_inode.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 8c99d35a2ed9f519476910f29e17501f3a67b140
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Thu Feb 27 13:57:53 2014 +0900

    f2fs: remove costly bit operations for f2fs_find_entry

    It turns out that a bit operation like find_next_bit is not always fast enough
    for f2fs_find_entry.
    Instead, it is pretty much simple and fast to traverse each dentries.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 601b829b3685a47b50a374e6a034397e0ef660b9
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Mon Feb 24 13:00:13 2014 +0900

    f2fs: implement a lock-free stat_show

    The stat_show is just to show the current status of f2fs.
    So, we can remove all the there-in locks.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 2e611ed7aebd169f8c039b11c656d88698ce7a66
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Fri Feb 21 14:29:35 2014 +0900

    f2fs: introduce a radix_tree for the free_nid list

    This patch introduces a radix tree for the list of free_nids, which enhances
    the performance on free nid management.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 2fea364d9d6ffdb563b31d5dc48cdf8cca65091f
Author: Gu Zheng <guz.fnst@cn.fujitsu.com>
Date:   Fri Feb 21 18:08:29 2014 +0800

    f2fs: introduce help macro on_build_free_nids()

    Introduce help macro on_build_free_nids() which just uses build_lock
    to judge whether the building free nid is going, so that we can remove
    the on_build_free_nids field from f2fs_sb_info.

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    [Jaegeuk Kim: remove an unnecessary white line removal]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 156018a44000c0e138f030089f6c34950467df41
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Fri Feb 21 13:17:22 2014 +0900

    f2fs: fix to mark the checkpointed nat entry correctly

    The nat cache entry maintains a status whether it is checkpointed or not.
    So, if a new cache entry is loaded from the last checkpoint,
    nat_entry->checkpointed should be true.
    If the cache entry is modified as being dirty, nat_entry->checkpoint should
    be false.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 7a3dd911308e4be21efc62587a17450557c6e9e9
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Feb 19 18:23:32 2014 +0900

    f2fs: fix to do build_stat prior to the recovery procedure

    At the end of the recovery procedure, write_checkpoint is called and updates
    the cp count which is managed by f2fs stat.
    But, previously build_stat() is called after the recovery procedure, which
    results in:

    BUG: unable to handle kernel NULL pointer dereference at 000000000000012c
    IP: [<ffffffffa03b1030>] write_checkpoint+0x720/0xbc0 [f2fs]
    Call Trace:
     [<ffffffff810a6b44>] ? mark_held_locks+0x74/0x140
     [<ffffffff8109a3e0>] ? __init_waitqueue_head+0x60/0x60
     [<ffffffffa03bf036>] recover_fsync_data+0x656/0xf20 [f2fs]
     [<ffffffff812ee3eb>] ? security_d_instantiate+0x1b/0x30
     [<ffffffffa03aeb4d>] f2fs_fill_super+0x94d/0xa00 [f2fs]
     [<ffffffff811a9825>] mount_bdev+0x1a5/0x1f0
     [<ffffffff8114915e>] ? __get_free_pages+0xe/0x40
     [<ffffffffa03ae200>] ? f2fs_remount+0x130/0x130 [f2fs]
     [<ffffffffa03aa575>] f2fs_mount+0x15/0x20 [f2fs]
     [<ffffffff811aa713>] mount_fs+0x43/0x1b0
     [<ffffffff811c7124>] vfs_kern_mount+0x74/0x160
     [<ffffffff811c5cb1>] ? __get_fs_type+0x51/0x60
     [<ffffffff811c9727>] do_mount+0x237/0xb50
     [<ffffffff811c936a>] ? copy_mount_options+0x3a/0x170

    So, this patche changes the order of recovery_fsync_data() and
    f2fs_build_stats().

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit be36d3e7a93a793d529b34f204b4b04ca4aac7b0
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Mon Feb 17 19:29:27 2014 +0900

    f2fs: fix not to write data pages on the page reclaiming path

    Even if f2fs_write_data_page is called by the page reclaiming path, we should
    not write the page to provide enough free segments for the worst case scenario.
    Otherwise, f2fs can face with no free segment while gc is conducted, resulting
    in:

     ------------[ cut here ]------------
     kernel BUG at /home/zeus/f2fs_test/src/fs/f2fs/segment.c:565!
     RIP: 0010:[<ffffffffa02c3b11>]  [<ffffffffa02c3b11>] new_curseg+0x331/0x340 [f2fs]
     Call Trace:
      allocate_segment_by_default+0x204/0x280 [f2fs]
      allocate_data_block+0x108/0x210 [f2fs]
      write_data_page+0x8a/0xc0 [f2fs]
      do_write_data_page+0xe1/0x2a0 [f2fs]
      move_data_page+0x8a/0xf0 [f2fs]
      f2fs_gc+0x446/0x970 [f2fs]
      f2fs_balance_fs+0xb6/0xd0 [f2fs]
      f2fs_write_begin+0x50/0x350 [f2fs]
      ? unlock_page+0x27/0x30
      ? unlock_page+0x27/0x30
      generic_file_buffered_write+0x10a/0x280
      ? file_update_time+0xa3/0xf0
      __generic_file_aio_write+0x1c8/0x3d0
      ? generic_file_aio_write+0x52/0xb0
      ? generic_file_aio_write+0x52/0xb0
      generic_file_aio_write+0x65/0xb0
      do_sync_write+0x5a/0x90
      vfs_write+0xc5/0x1f0
      SyS_write+0x55/0xa0
      system_call_fastpath+0x16/0x1b

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 97dffcb71efd7fc20406784fd1d38f0b13b28880
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Mon Feb 17 12:44:20 2014 +0900

    f2fs: fix the calculation of max_nids

    Total nids that f2fs can use should not include 0, nid for node inode, and nid
    for meta inode.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 296501929ec16c4c2a5fa0a4e1efd55ae7a2cd98
Author: Changman Lee <cm224.lee@samsung.com>
Date:   Thu Feb 13 15:12:29 2014 +0900

    f2fs: show counts of checkpoint in status

    This patch shows the counts of checkpoint in f2fs' status.

    Signed-off-by: Changman Lee <cm224.lee@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 5e749f155750b173c10eddc7d6d728ce92295071
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Fri Feb 7 16:11:53 2014 +0800

    f2fs: introduce ra_meta_pages to readahead CP/NAT/SIT pages

    This patch help us to cleanup the readahead code by merging ra_{sit,nat}_pages
    function into ra_meta_pages.
    Additionally the new function is used to readahead cp block in
    recover_orphan_inodes.

    Change log from v1:
     o fix a deadloop bug pointed by Jaegeuk Kim.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit c1823ca03aefb2786996e2ebeeba5846b8899a05
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Tue Jan 28 10:29:26 2014 +0800

    f2fs: use inode mutex to keep atomicity of f2fs_falloc

    Previously without protection of inode mutex, f2fs_falloc and other data
    correlated operations will interfere with each other.
    So let's use inode mutex to keep atomicity of f2fs_falloc.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit ab7df6d7e76714d95aaf26a584d1ec6cea1ecff4
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Fri Feb 7 10:00:06 2014 +0900

    f2fs: clean up redundant function call

    This patch integrates inode_[inc|dec]_dirty_dents with inc_page_count to remove
    redundant calls.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 61ebcb665265d7ee328fe050fc4c34c71f333307
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Feb 5 13:03:57 2014 +0900

    f2fs: fix f2fs_write_meta_page at no checkpoint status

    If f2fs entered errorneous checkpoint status, it should skip writing meta
    pages instead of redirtying the pages out.
    Otherwise, it cannot unmount the partition even though f2fs is under read-only
    status.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 63cf16d5b82fd243ce5ebe429a36fdb7e8a3bac9
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Wed Feb 5 11:16:39 2014 +0900

    f2fs: fix to truncate dentry pages in the error case

    When a new directory is allocated, if an error is occurred, we should truncate
    preallocated dentry pages too.

    This bug was reported by Andrey Tsyvarev after a while as follows.

    mkdir()->
     f2fs_add_link()->
      init_inode_metadata()->
        f2fs_init_acl()->
          f2fs_get_acl()->
            f2fs_getxattr()->
              read_all_xattrs() fails.

    Also there was a BUG_ON triggered after the fault in
    mkdir()->
     f2fs_add_link()->
       init_inode_metadata()->
        remove_inode_page() ->
          f2fs_bug_on(inode->i_blocks != 0 && inode->i_blocks != 1);

    But, previous patch wasn't perfect to resolve that bug, so the following bug
    report was also submitted.

    kernel BUG at fs/f2fs/inode.c:274!
    Call Trace:
     [<ffffffff811fde03>] evict+0xa3/0x1a0
     [<ffffffff811fe615>] iput+0xf5/0x180
     [<ffffffffa01c7f63>] f2fs_mkdir+0xf3/0x150 [f2fs]
     [<ffffffff811f2a77>] vfs_mkdir+0xb7/0x160
     [<ffffffff811f36bf>] SyS_mkdir+0x5f/0xc0
     [<ffffffff81680769>] system_call_fastpath+0x16/0x1b

    Finally, this patch resolves all the issues like below.

    If an error is occurred after make_empty_dir(),
     1. truncate_inode_pages()
       The make_bad_inode() prior to iput() will change i_mode to S_IFREG, which
       means that f2fs will not decrement fi->dirty_dents during f2fs_evict_inode.
       But, by calling it here, we can do that.

     2. truncate_blocks()
       Preallocated dentry pages are trucated here to sync i_blocks.

     3. remove_dirty_dir_inode()
       Remove this directory inode from the list.

    Reported-and-Tested-by: Andrey Tsyvarev <tsyvarev@ispras.ru>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 55b33e17da12f38ea81d59ed9fbfa31cbe33f4b2
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Jan 28 14:54:07 2014 +0900

    f2fs: fix a build warning

    This patch modifies flow a little bit to avoid the following build warnings.

    src/fs/f2fs/recovery.c: In function ‘check_index_in_prev_nodes’:
    src/fs/f2fs/recovery.c:288:51: warning: ‘sum.<U5390>.<U52f8>.ofs_in_node’ may
    	be used uninitialized in this function [-Wmaybe-uninitialized]
    src/fs/f2fs/recovery.c:260:23: warning: ‘sum.nid’ may be used uninitialized
    	in this function [-Wmaybe-uninitialized]

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit dd1c7a0fc85e83d9bb41f04824f0801dc4889148
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Feb 4 13:01:10 2014 +0900

    f2fs: clean up with a macro

    This patch adds GET_BLKOFF_FROM_SEG0 to clean up some codes.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 10ec7dc92dc37d28a4163f20fe365c10644f8486
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Mon Feb 3 17:24:51 2014 +0900

    f2fs: fix the potential mismatch between dir's i_size and i_blocks

    This is the erroneous scenario.

                                 i_size    on-disk i_size    i_blocks
    __f2fs_add_link()             4096           4096           2
     get_new_data_page            8192           4096           3
     -ENOSPC = init_inode_metadata
     checkpoint                     -            4096           3
     POR and reboot

    __f2fs_add_link()             4096           4096           3
     page = get_new_data_page (page->index = 1 by NEW_ADDR)
     add a dentry to the page successfully

    f2fs_rmdir()
     f2fs_empty_dir()             4096           4096           3
     f2fs_unlink() goes, since there is no valid dentry due to i_size = 4096.
     But, still there is one dentry in page->index = 1.

    So this patch moves the code to write dir->i_size into on-disk i_size in order
    to sync dir's i_size, on-disk i_size, and its i_blocks.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 448b6d4a7c2a5bd6ff536ec0c7a0b0b54a8609c1
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Mon Feb 3 10:50:22 2014 +0900

    f2fs: remove the ugly pointer conversion

    This patch modifies the use of bi_private to remove pointer chasing for sbi.
    Previously, we had a bi_private structure, but it needs memory allocation.
    So this patch uses bi_private by the sbi pointer and adds a completion pointer
    into the sbi.
    This can achieve no memory allocation and nice use of the bi_private.

    Change-Id: I1546c1e7f991f8eebe9323d6930a5919d18773cb
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 86b39e747db7250d8fdfd9dd147e68266ab674db
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Jan 28 12:25:06 2014 +0900

    f2fs: fix to recover xattr node block

    If a new xattr node page was allocated and its inode is fsynced, we should
    recover the xattr node page during the roll-forward process after power-cut.
    But, previously, f2fs didn't handle that case, resulting in kernel panic as
    follows reported by Tom Li.

    BUG: unable to handle kernel paging request at ffffc9001c861a98
    IP: [<ffffffffa0295236>] check_index_in_prev_nodes+0x86/0x2d0 [f2fs]
    Call Trace:
     [<ffffffff815ece9b>] ? printk+0x48/0x4a
     [<ffffffffa029626a>] recover_fsync_data+0xdca/0xf50 [f2fs]
     [<ffffffffa02873ae>] f2fs_fill_super+0x92e/0x970 [f2fs]
     [<ffffffff8112c9f8>] mount_bdev+0x1b8/0x200
     [<ffffffffa0286a80>] ? f2fs_remount+0x130/0x130 [f2fs]
     [<ffffffffa0285e40>] f2fs_mount+0x10/0x20 [f2fs]
     [<ffffffff8112d4de>] mount_fs+0x3e/0x1b0
     [<ffffffff810ef4eb>] ? __alloc_percpu+0xb/0x10
     [<ffffffff8114761f>] vfs_kern_mount+0x6f/0x120
     [<ffffffff811497b9>] do_mount+0x259/0xa90
     [<ffffffff810ead1d>] ? memdup_user+0x3d/0x80
     [<ffffffff810eadb3>] ? strndup_user+0x53/0x70
     [<ffffffff8114a2c9>] SyS_mount+0x89/0xd0
     [<ffffffff815feae2>] system_call_fastpath+0x16/0x1b

    This patch adds a recovery function of xattr node pages.

    Reported-by: Tom Li <biergaizi@members.fsf.org>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 53dfc19a334b6d5a6922e627ae1fb15d86183e5a
Author: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Date:   Tue Jan 28 12:22:14 2014 +0900

    f2fs: handle dirty segments inside refresh_sit_entry

    This patch cleans up the refresh_sit_entry to handle locate_dirty_segments.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

commit 81efaeaa7e0182df42e6bd462097dbdb87ede7ff
Author: Changman Lee <cm224.lee@samsung.com>
Date:   Fri Nov 15 10:42:51 2013 +0900

    f2fs: Update to version in 3.14

    f2fs: introduce __find_rev_next(_zero)_bit

    When f2fs_set_bit is used, in a byte MSB and LSB is reversed,
    in that case we can use __find_rev_next_bit or __find_rev_next_zero_bit.

    Signed-off-by: Changman Lee <cm224.lee@samsung.com>
    [Jaegeuk Kim: change the function names]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: improve searching speed of __next_free_blkoff

    To find a zero bit using the result of OR operation between ckpt_valid_map
    and cur_valid_map is more fast than find a zero bit in each bitmap.

    Signed-off-by: Changman Lee <cm224.lee@samsung.com>
    [Jaegeuk Kim: adjust changed function name]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add a slab cache entry for small discards

    This patch adds a slab cache entry for small discards.

    Each entry consists of:

    struct discard_entry {
    	struct list_head list;	/* list head */
    	block_t blkaddr;	/* block address to be discarded */
    	int len;		/* # of consecutive blocks of the discard */
    };

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add key functions for small discards

    This patch adds key functions to activate the small discard feature.

    Note that this procedure is conducted during the checkpoint only.

    In flush_sit_entries(), when a new dirty sit entry is flushed, f2fs calls
    add_discard_addrs() which searches candidates to be discarded.
    The candidates should be marked *invalidated* and also previous checkpoint
    recognizes it as *valid*.

    At the end of a checkpoint procedure, f2fs throws discards based on the
    discard entry list.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add a sysfs entry to control max_discards

    If frequent small discards are issued to the device, the performance would
    be degraded significantly.
    So, this patch adds a sysfs entry to control the number of discards to be
    issued during a checkpoint procedure.

    By default, f2fs does not issue any small discards, which means max_discards
    is zero.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: introduce f2fs_issue_discard() to clean up

    Change log from v1:
     o fix 32bit drops reported by Dan Carpenter

    This patch adds f2fs_issue_discard() to clean up blkdev_issue_discard() flows.

    Dan carpenter reported:
    "block_t is a 32 bit type and sector_t is a 64 bit type.  The upper 32
    bits of the sector_t are not used because the shift will wrap."

    Bug-Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add a tracepoint for f2fs_issue_discard

    This patch adds a tracepoint for f2fs_issue_discard.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: use f2fs_put_page to release page for uniform style

    We should use f2fs_put_page to release page for uniform style of f2fs code.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: clean up the do_submit_bio flow

    This patch introduces PAGE_TYPE_OF_BIO() and cleans up do_submit_bio() with it.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: use sbi->write_mutex for write bios

    This patch removes an unnecessary semaphore (i.e., sbi->bio_sem).
    There is no reason to use the semaphore when f2fs submits read and write IOs.
    Instead, let's use a write mutex and cover the sbi->bio[] by the lock.

    Change log from v1:
     o split write_mutex suggested by Chao Yu

    Chao described,
    "All DATA/NODE/META bio buffers in superblock is protected by
    'sbi->write_mutex', but each bio buffer area is independent, So we
    should split write_mutex to three for DATA/NODE/META."

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: disable the extent cache ops on high fragmented files

    The f2fs manages an extent cache to search a number of consecutive data blocks
    very quickly.

    However it conducts unnecessary cache operations if the file is highly
    fragmented with no valid extent cache.

    In such the case, we don't need to handle the extent cache, but just can disable
    the cache facility.

    Nevertheless, this patch gives one more chance to enable the extent cache.

    For example,
    1. create a file
    2. write data sequentially which produces a large valid extent cache
    3. update some data, resulting in a fragmented extent
    4. if the fragmented extent is too small, then drop extent cache
    5. close the file

    6. open the file again
    7. give another chance to make a new extent cache
    8. write data sequentially again which creates another big extent cache.
    ...

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: introduce a bio array for per-page write bios

    The f2fs has three bio types, NODE, DATA, and META, and manages some data
    structures per each bio types.

    The codes are a little bit messy, thus, this patch introduces a bio array
    which groups individual data structures as follows.

    struct f2fs_bio_info {
    	struct bio *bio;		/* bios to merge */
    	sector_t last_block_in_bio;	/* last block number */
    	struct mutex io_mutex;		/* mutex for bio */
    };

    struct f2fs_sb_info {
    	...
    	struct f2fs_bio_info write_io[NR_PAGE_TYPE];	/* for write bios */
    	...
    };

    The code changes from this new data structure are trivial.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: convert remove_inode_page to void

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: convert dev_valid_block_count to void

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: convert inc/dec_valid_node_count to inc/dec one count

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: simplify write_orphan_inodes for better readable

    Simplify write_orphan_inodes for better readable. Because we hold the
    orphan_inode_mutex, so it's safe to use list_for_each_entry instead of
    list_for_each_safe.

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: move the list_head initialization into the lock protection region

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add a new function to support for merging contiguous read

    For better read performance, we add a new function to support for merging
    contiguous read as the one for write.

    v1-->v2:
     o add declarations here as Gu Zheng suggested.
     o use new structure f2fs_bio_info introduced by Jaegeuk Kim.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Acked-by: Gu Zheng <guz.fnst@cn.fujitsu.com>

    f2fs: merge read IOs at ra_nat_pages()

    Change log from v1:
      o add mark_page_accessed() not to reclaim the nat pages.

    This patch changes the policy of submitting read bios at ra_nat_pages.

    Previously, f2fs submits small read bios with block plugging.
    But, with this patch, f2fs itself merges read bios first and then submits a
    large bio, which can reduce the bio handling overheads.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: simplify IS_DATASEG and IS_NODESEG macro

    It is not efficient comparing each segment type to find node or data.

    Signed-off-by: Changman Lee <cm224.lee@samsung.com>
    [Jaegeuk Kim: remove unnecessary white spaces]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: adds a tracepoint for submit_read_page

    This patch adds a tracepoint for submit_read_page.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    [Jaegeuk Kim: integrate tracepoints of f2fs_submit_read(_write)_page]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: adds a tracepoint for f2fs_submit_read_bio

    This patch adds a tracepoint for f2fs_submit_read_bio.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    [Jaegeuk Kim: integrate tracepoints of f2fs_submit_read(_write)_bio]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: read contiguous sit entry pages by merging for mount performance

    Previously we read sit entries page one by one, this method lost the chance
    of reading contiguous page together. So we read pages as contiguous as
    possible for better mount performance.

    change log:
     o merge judgements/use 'Continue' or 'Break' instead of 'Goto' as Gu Zheng
       suggested.
     o add mark_page_accessed() before release page to delay VM reclaiming.
     o remove '*order' for simplification of function as Jaegeuk Kim suggested.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    [Jaegeuk Kim: fix a bug on the block address calculation]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: avoid lock debugging overhead

    If CONFIG_F2FS_CHECK_FS is unset, we don't need to add any debugging overhead.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add a new function: f2fs_reserve_block()

    Add the function f2fs_reserve_block() to easily reserve new blocks, and
    use it to clean up more codes.

    Signed-off-by: Huajun Li <huajun.li@intel.com>
    Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
    Signed-off-by: Weihong Xu <weihong.xu@intel.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add detailed information of bio types in the tracepoints

    This patch inserts information of bio types in more detail.
    So, we can now see REQ_META and REQ_PRIO too.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: send REQ_META or REQ_PRIO when reading meta area

    Let's send REQ_META or REQ_PRIO when reading meta area such as NAT/SIT
    etc.

    Signed-off-by: Changman Lee <cm224.lee@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add flags and helpers to support inline data

    Add new inode flags F2FS_INLINE_DATA and FI_INLINE_DATA to indicate
    whether the inode has inline data.

    Inline data makes use of inode block's data indices region to save small
    file. Currently there are 923 data indices in an inode block. Since
    inline xattr has made use of the last 50 indices to save its data, there
    are 873 indices left which can be used for inline data. When
    FI_INLINE_DATA is set, the layout of inode block's indices region is
    like below:

    +-----------------+
    |                 | Reserved. reserve_new_block() will make use of
    | i_addr[0]       | i_addr[0] when we need to reserve a new data block
    |                 | to convert inline data into regular one's.
    |-----------------|
    |                 | Used by inline data. A file whose size is less than
    | i_addr[1~872]   | 3488 bytes(~3.4k) and doesn't reserve extra
    |                 | blocks by fallocate() can be saved here.
    |-----------------|
    |                 |
    | i_addr[873~922] | Reserved for inline xattr
    |                 |
    +-----------------+

    Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
    Signed-off-by: Huajun Li <huajun.li@intel.com>
    Signed-off-by: Weihong Xu <weihong.xu@intel.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add a new mount option: inline_data

    Add a mount option: inline_data. If the mount option is set,
    data of New created small files can be stored in their inode.

    Signed-off-by: Huajun Li <huajun.li@intel.com>
    Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
    Signed-off-by: Weihong Xu <weihong.xu@intel.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: remove unnecessary return value

    Let's remove the unnecessary return value.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: fix a potential out of range issue

    Fix a potential out of range issue introduced by commit:
    22fb72225a
    f2fs: simplify write_orphan_inodes for better readable

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: bug fix on bit overflow from 32bits to 64bits

    This patch fixes some bit overflows by the shift operations.

    Dan Carpenter reported potential bugs on bit overflows as follows.

    fs/f2fs/segment.c:910 submit_write_page()
    	warn: should 'blk_addr << ((sbi)->log_blocksize - 9)' be a 64 bit type?
    fs/f2fs/checkpoint.c:429 get_valid_checkpoint()
    	warn: should '1 << ()' be a 64 bit type?
    fs/f2fs/data.c:408 f2fs_readpage()
    	warn: should 'blk_addr << ((sbi)->log_blocksize - 9)' be a 64 bit type?
    fs/f2fs/data.c:457 submit_read_page()
    	warn: should 'blk_addr << ((sbi)->log_blocksize - 9)' be a 64 bit type?
    fs/f2fs/data.c:525 get_data_block_ro()
    	warn: should 'i << blkbits' be a 64 bit type?

    Bug-Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: remove unnecessary condition checks

    This patch removes the unnecessary condition checks on:

    fs/f2fs/gc.c:667 do_garbage_collect() warn: 'sum_page' isn't an ERR_PTR
    fs/f2fs/f2fs.h:795 f2fs_put_page() warn: 'page' isn't an ERR_PTR

    Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: remove unneeded code in punch_hole

    Because FALLOC_FL_PUNCH_HOLE flag must be ORed with FALLOC_FL_KEEP_SIZE
    in fallocate, so we could remove the useless 'keep size' branch code which
    will never be excuted in punch_hole.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Fan Li <fanofcode.li@samsung.com>
    [Jaegeuk Kim: remove an unnecessary parameter togather]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: avoid to calculate incorrect max orphan number

    Because we will write node summaries when do_checkpoint with umount flag,
    our number of max orphan blocks should minus NR_CURSEG_NODE_TYPE additional.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Shu Tan <shu.tan@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: correct type of wait in struct bio_private

    The void *wait in bio_private is used for waiting completion of checkpoint bio.
    So we don't need to use its type as void, but declare it as completion type.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    [Jaegeuk Kim: add description]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: use true and false for boolean variable

    The inode_page_locked should be a boolean variable.

    struct dnode_of_data {
    	struct inode *inode;            /* vfs inode pointer */
    	struct page *inode_page;        /* its inode page, NULL is possible */
    	struct page *node_page;         /* cached direct node page */
    	nid_t nid;                      /* node id of the direct node block */
    	unsigned int ofs_in_node;       /* data offset in the node page */
    ==>	bool inode_page_locked;         /* inode page is locked or not */
    	block_t data_blkaddr;           /* block address of the node block */
    };

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    [Jaegeuk Kim: add description]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: check return value of f2fs_readpage in find_data_page

    We should return error if we do not get an updated page in find_date_page
    when f2fs_readpage failed.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: convert recover_orphan_inodes to void

    The recover_orphan_inodes() returns no error all the time, so we don't need to
    check its errors.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    [Jaegeuk Kim: add description]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: remove the own bi_private allocation

    Previously f2fs allocates its own bi_private data structure all the time even
    though we don't use it. But, can we remove this bi_private allocation?

    This patch removes such the additional bi_private allocation.

    1. Retrieve f2fs_sb_info from its page->mapping->host->i_sb.
     - This removes the usecases of bi_private in end_io.

    2. Use bi_private only when we really need it.
     - The bi_private is used only when the checkpoint procedure is conducted.
     - When conducting the checkpoint, f2fs submits a META_FLUSH bio to wait its bio
    completion.
     - Since we have no dependancies to remove bi_private now, let's just use
     bi_private pointer as the completion pointer.

    Reviewed-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: refactor bio-related operations

    This patch integrates redundant bio operations on read and write IOs.

    1. Move bio-related codes to the top of data.c.
    2. Replace f2fs_submit_bio with f2fs_submit_merged_bio, which handles read
       bios additionally.
    3. Introduce __submit_merged_bio to submit the merged bio.
    4. Change f2fs_readpage to f2fs_submit_page_bio.
    5. Introduce f2fs_submit_page_mbio to integrate previous submit_read_page and
       submit_write_page.

    Reviewed-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Reviewed-by: Chao Yu <chao2.yu@samsung.com >
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: readahead contiguous pages for restore_node_summary

    If cp has no CP_UMOUNT_FLAG, we will read all pages in whole node segment
    one by one, it makes low performance. So let's merge contiguous pages and
    readahead for better performance.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    [Jaegeuk Kim: adjust the new bio operations]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: remove debufs dir if debugfs_create_file() failed

    When debugfs_create_file() failed in f2fs_create_root_stats(),
    debugfs_root should be remove.

    Signed-off-by: Younger Liu <liuyiyang@hisense.com>
    Cc: Younger Liu <younger.liucn@gmail.com>
    Cc: Jaegeuk Kim <jaegeuk.kim@samsung.com>
    Reviewed-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: replace the debugfs_root with f2fs_debugfs_root

    This minor change for the naming conventions of debugfs_root
    to avoid any possible conflicts to the other filesystem.

    Signed-off-by: Younger Liu <younger.liucn@gmail.com>
    Cc: Younger Liu <younger.liucn@gmail.com>
    Cc: Jaegeuk Kim <jaegeuk.kim@samsung.com>
    [Jaegeuk Kim: change the patch name]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: use inner macro GFP_F2FS_ZERO for simplification

    Use inner macro GFP_F2FS_ZERO to instead of GFP_NOFS | __GFP_ZERO for
    simplification of code.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: avoid unneeded page release for correct _count of page

    In find_fsync_dnodes() and recover_data(), our flow is like this:

    ->f2fs_submit_page_bio()
    	-> f2fs_put_page()
    		-> page_cache_release()	---- page->_count declined to zero.
    ->__free_pages()
    	-> put_page_testzero() ---- page->_count will be declined again.

    We will get a segment fault in put_page_testzero when CONFIG_DEBUG_VM
    is on, or return MM with a bad page with wrong _count num.

    So let's just release this page.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add unlikely() macro for compiler optimization

    As we know, some of our branch condition will rarely be true. So we could add
    'unlikely' to let compiler optimize these code, by this way we could drop
    unneeded 'jump' assemble code to improve performance.

    change log:
     o add *unlikely* as many as possible across the whole source files at once
       suggested by Jaegeuk Kim.

    Suggested-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add unlikely() macro for compiler more aggressively

    This patch adds unlikely() macro into the most of codes.
    The basic rule is to add that when:
    - checking unusual errors,
    - checking page mappings,
    - and the other unlikely conditions.

    Change log from v1:
     - Don't add unlikely for the NULL test and error test: advised by Andi Kleen.

    Cc: Chao Yu <chao2.yu@samsung.com>
    Cc: Andi Kleen <andi@firstfloor.org>
    Reviewed-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: merge pages with the same sync_mode flag

    Previously f2fs submits most of write requests using WRITE_SYNC, but f2fs_write_data_pages
    submits last write requests by sync_mode flags callers pass.

    This causes a performance problem since continuous pages with different sync flags
    can't be merged in cfq IO scheduler(thanks yu chao for pointing it out), and synchronous
    requests often take more time.

    This patch makes the following modifies to DATA writebacks:

    1. every page will be written back using the sync mode caller pass.
    2. only pages with the same sync mode can be merged in one bio request.

    These changes are restricted to DATA pages.Other types of writebacks are modified
    To remain synchronous.

    In my test with tiotest, f2fs sequence write performance is improved by about 7%-10% ,
    and this patch has no obvious impact on other performance tests.

    Signed-off-by: Fan Li <fanofcode.li@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: refactor bio->rw handling

    This patch introduces f2fs_io_info to mitigate the complex parameter list.

    struct f2fs_io_info {
    	enum page_type type;		/* contains DATA/NODE/META/META_FLUSH */
    	int rw;				/* contains R/RS/W/WS */
    	int rw_flag;			/* contains REQ_META/REQ_PRIO */
    }

    1. f2fs_write_data_pages
     - DATA
     - WRITE_SYNC is set when wbc->WB_SYNC_ALL.

    2. sync_node_pages
     - NODE
     - WRITE_SYNC all the time

    3. sync_meta_pages
     - META
     - WRITE_SYNC all the time
     - REQ_META | REQ_PRIO all the time

     ** f2fs_submit_merged_bio() handles META_FLUSH.

    4. ra_nat_pages, ra_sit_pages, ra_sum_pages
     - META
     - READ_SYNC

    Cc: Fan Li <fanofcode.li@samsung.com>
    Cc: Changman Lee <cm224.lee@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: fix the location of tracepoint

    We need to get a trace before submit_bio, since its bi_sector is remapped during
    the submit_bio.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: missing kmem_cache_destroy for discard_entry

    insmod f2fs.ko is failed after insmod and rmmod firstly.

    $ sudo insmod fs/f2fs/f2fs.ko
    insmod: error inserting 'fs/f2fs/f2fs.ko': -1 Cannot allocate memory

    -- dmesg --
    kmem_cache_sanity_check (free_nid): Cache name already exists.

    Signed-off-by: Changman Lee <cm224.lee@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: introduce sysfs entry to control in-place-update policy

    This patch introduces new sysfs entries for users to control the policy of
    in-place-updates, namely IPU, in f2fs.

    Sometimes f2fs suffers from performance degradation due to its out-of-place
    update policy that produces many additional node block writes.
    If the storage performance is very dependant on the amount of data writes
    instead of IO patterns, we'd better drop this out-of-place update policy.

    This patch suggests 5 polcies and their triggering conditions as follows.

    [sysfs entry name = ipu_policy]

    0: F2FS_IPU_FORCE       all the time,
    1: F2FS_IPU_SSR         if SSR mode is activated,
    2: F2FS_IPU_UTIL        if FS utilization is over threashold,
    3: F2FS_IPU_SSR_UTIL    if SSR mode is activated and FS utilization is over
                            threashold,
    4: F2FS_IPU_DISABLE    disable IPU. (=default option)

    [sysfs entry name = min_ipu_util]

    This parameter controls the threshold to trigger in-place-updates.
    The number indicates percentage of the filesystem utilization, and used by
    F2FS_IPU_UTIL and F2FS_IPU_SSR_UTIL policies.

    For more details, see need_inplace_update() in segment.h.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: introduce a new direct_IO write path

    Previously, f2fs doesn't support direct IOs with high performance, which throws
    every write requests via the buffered write path, resulting in highly
    performance degradation due to memory opeations like copy_from_user.

    This patch introduces a new direct IO path in which every write requests are
    processed by generic blockdev_direct_IO() with enhanced get_block function.

    The get_data_block() in f2fs handles:
    1. if original data blocks are allocates, then give them to blockdev.
    2. otherwise,
      a. preallocate requested block addresses
      b. do not use extent cache for better performance
      c. give the block addresses to blockdev

    This policy induces that:
    - new allocated data are sequentially written to the disk
    - updated data are randomly written to the disk.
    - f2fs gives consistency on its file meta, not file data.

    Reviewed-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: write dirty meta pages collectively

    This patch enhances writing dirty meta pages collectively in background.
    During the file data writes, it'd better avoid to write small dirty meta pages
    frequently.
    So let's give a chance to collect a number of dirty meta pages for a while.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: move all the bio initialization into __bio_alloc

    Move all the bio initialization into __bio_alloc, and some minor cleanups are
    also added.

    v3:
      Use 'bool' rather than 'int' as Kim suggested.

    v2:
      Use 'is_read' rather than 'rw' as Yu Chao suggested.
      Remove the needless initialization of bio->bi_private.

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: remove the rw_flag domain from f2fs_io_info

    When using the f2fs_io_info in the low level, we still need to merge the
    rw and rw_flag, so use the rw to hold all the io flags directly,
    and remove the rw_flag field.

    ps.It is based on the previous patch:
    f2fs: move all the bio initialization into __bio_alloc

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: update several comments

    Update several comments:
    1. use f2fs_{un}lock_op install of mutex_{un}lock_op.
    2. update comment of get_data_block().
    3. update description of node offset.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: avoid to set wrong pino of inode when rename dir

    When we rename a dir to new name which is not exist previous,
    we will set pino of parent inode with ino of child inode in f2fs_set_link.
    It destroy consistency of pino, it should be fixed.

    Thanks for previous work of Shu Tan.

    Signed-off-by: Shu Tan <shu.tan@samsung.com>
    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: check filename length in recover_dentry

    In current flow, we will get Null return value of f2fs_find_entry in
    recover_dentry when name.len is bigger than F2FS_NAME_LEN, and then we
    still add this inode into its dir entry.
    To avoid this situation, we must check filename length before we use it.

    Another point is that we could remove the code of checking filename length
    In f2fs_find_entry, because f2fs_lookup will be called previously to ensure of
    validity of filename length.

    V2:
     o add WARN_ON() as Jaegeuk Kim suggested.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: introduce F2FS_INODE macro to get f2fs_inode

    This patch introduces F2FS_INODE that returns struct f2fs_inode * from the inode
    page.
    By using this macro, we can remove unnecessary casting codes like below.

       struct f2fs_inode *ri = &F2FS_NODE(inode_page)->i;
    -> struct f2fs_inode *ri = F2FS_INODE(inode_page);

    Reviewed-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: should put the dnode when NEW_ADDR is detected

    When get_dnode_of_data() in get_data_block() returns a successful dnode, we
    should put the dnode.
    But, previously, if its data block address is equal to NEW_ADDR, we didn't do
    that, resulting in a deadlock condition.
    So, this patch splits original error conditions with this case, and then calls
    f2fs_put_dnode before finishing the function.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: check the blocksize before calling generic_direct_IO path

    The f2fs supports 4KB block size. If user requests dwrite with under 4KB data,
    it allocates a new 4KB data block.
    However, f2fs doesn't add zero data into the untouched data area inside the
    newly allocated data block.

    This incurs an error during the xfstest #263 test as follow.

    263 12s ... [failed, exit status 1] - output mismatch (see 263.out.bad)
    	--- 263.out	2013-03-09 03:37:15.043967603 +0900
    	+++ 263.out.bad	2013-12-27 04:20:39.230203114 +0900
    	@@ -1,3 +1,976 @@
    	QA output created by 263
    	fsx -N 10000 -o 8192 -l 500000 -r PSIZE -t BSIZE -w BSIZE -Z
    	-fsx -N 10000 -o 128000 -l 500000 -r PSIZE -t BSIZE -w BSIZE -Z
    	+fsx -N 10000 -o 8192 -l 500000 -r PSIZE -t BSIZE -w BSIZE -Z
    	+truncating to largest ever: 0x12a00
    	+truncating to largest ever: 0x75400
    	+fallocating to largest ever: 0x79cbf
    	...
    	(Run 'diff -u 263.out 263.out.bad' to see the entire diff)
    	Ran: 263
    	Failures: 263
    	Failed 1 of 1 tests

    It turns out that, when the test tries to write 2KB data with dio, the new dio
    path allocates 4KB data block without filling zero data inside the remained 2KB
    area. Finally, the output file contains a garbage data for that region.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: convert max_orphans to a field of f2fs_sb_info

    Previously, we need to calculate the max orphan num when we try to acquire an
    orphan inode, but it's a stable value since the super block was inited. So
    converting it to a field of f2fs_sb_info and use it directly when needed seems
    a better choose.

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: key functions to handle inline data

    Functions to implement inline data read/write, and move inline data to
    normal data block when file size exceeds inline data limitation.

    Signed-off-by: Huajun Li <huajun.li@intel.com>
    Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
    Signed-off-by: Weihong Xu <weihong.xu@intel.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: handle inline data operations

    Hook inline data read/write, truncate, fallocate, setattr, etc.

    Files need meet following 2 requirement to inline:
     1) file size is not greater than MAX_INLINE_DATA;
     2) file doesn't pre-allocate data blocks by fallocate().

    FI_INLINE_DATA will not be set while creating a new regular inode because
    most of the files are bigger than ~3.4K. Set FI_INLINE_DATA only when
    data is submitted to block layer, ranther than set it while creating a new
    inode, this also avoids converting data from inline to normal data block
    and vice versa.

    While writting inline data to inode block, the first data block should be
    released if the file has a block indexed by i_addr[0].

    On the other hand, when a file operation is appied to a file with inline
    data, we need to test if this file can remain inline by doing this
    operation, otherwise it should be convert into normal file by reserving
    a new data block, copying inline data to this new block and clear
    FI_INLINE_DATA flag. Because reserve a new data block here will make use
    of i_addr[0], if we save inline data in i_addr[0..872], then the first
    4 bytes would be overwriten. This problem can be avoided simply by
    not using i_addr[0] for inline data.

    Signed-off-by: Huajun Li <huajun.li@intel.com>
    Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
    Signed-off-by: Weihong Xu <weihong.xu@intel.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: don't need to get f2fs_lock_op for the inline_data test

    This patch locates checking the inline_data prior to calling f2fs_lock_op()
    in truncate_blocks(), since getting the lock is unnecessary.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: convert inline_data for punch_hole

    In the punch_hole(), let's convert inline_data all the time for simplicity and
    to avoid potential deadlock conditions.
    It is pretty much not a big deal to do this.

    Reviewed-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: call f2fs_put_page at the error case

    In f2fs_write_begin(), if f2fs_conver_inline_data() returns an error like
    -ENOSPC, f2fs should call f2fs_put_page().
    Otherwise, it is remained as a locked page, resulting in the following bug.

    [<ffffffff8114657e>] sleep_on_page+0xe/0x20
    [<ffffffff81146567>] __lock_page+0x67/0x70
    [<ffffffff81157d08>] truncate_inode_pages_range+0x368/0x5d0
    [<ffffffff81157ff5>] truncate_inode_pages+0x15/0x20
    [<ffffffff8115804b>] truncate_pagecache+0x4b/0x70
    [<ffffffff81158082>] truncate_setsize+0x12/0x20
    [<ffffffffa02a1842>] f2fs_setattr+0x72/0x270 [f2fs]
    [<ffffffff811cdae3>] notify_change+0x213/0x400
    [<ffffffff811ab376>] do_truncate+0x66/0xa0
    [<ffffffff811ab541>] vfs_truncate+0x191/0x1b0
    [<ffffffff811ab5bc>] do_sys_truncate+0x5c/0xa0
    [<ffffffff811ab78e>] SyS_truncate+0xe/0x10
    [<ffffffff81756052>] system_call_fastpath+0x16/0x1b
    [<ffffffffffffffff>] 0xffffffffffffffff

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: refactor f2fs_convert_inline_data

    Change log from v1:
     o handle NULL pointer of grab_cache_page_write_begin() pointed by Chao Yu.

    This patch refactors f2fs_convert_inline_data to check a couple of conditions
    internally for deciding whether it needs to convert inline_data or not.

    So, the new f2fs_convert_inline_data initially checks:
    1) f2fs_has_inline_data(), and
    2) the data size to be changed.

    If the inode has inline_data but the size to fill is less than MAX_INLINE_DATA,
    then we don't need to convert the inline_data with data allocation.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add the number of inline_data files to status info

    This patch adds the number of inline_data files into the status information.
    Note that the number is reset whenever the filesystem is newly mounted.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add inline_data recovery routine

    This patch adds a inline_data recovery routine with the following policy.

    [prev.] [next] of inline_data flag
       o       o  -> recover inline_data
       o       x  -> remove inline_data, and then recover data blocks
       x       o  -> remove inline_data, and then recover inline_data
       x       x  -> recover data blocks

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: handle errors correctly during f2fs_reserve_block

    The get_dnode_of_data nullifies inode and node page when error is occurred.

    There are two cases that passes inode page into get_dnode_of_data().

    1. make_empty_dir()
        -> get_new_data_page()
          -> f2fs_reserve_block(ipage)
    	-> get_dnode_of_data()

    2. f2fs_convert_inline_data()
        -> __f2fs_convert_inline_data()
          -> f2fs_reserve_block(ipage)
    	-> get_dnode_of_data()

    This patch adds correct error handling codes when get_dnode_of_data() returns
    an error.

    At first, f2fs_reserve_block() calls f2fs_put_dnode() whenever reserve_new_block
    returns an error.
    So, the rule of f2fs_reserve_block() is to nullify inode page when there is any
    error internally.

    Finally, two callers of f2fs_reserve_block() should call f2fs_put_dnode()
    appropriately if they got an error since successful f2fs_reserve_block().

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: fix truncate_partial_nodes bug

    The truncate_partial_nodes puts pages incorrectly in the following two cases.
    Note that the value for argc 'depth' can only be 2 or 3.
    Please see truncate_inode_blocks() and truncate_partial_nodes().

    1) An err is occurred in the first 'for' loop
      When err is occurred with depth = 2, pages[0] is invalid, so this page doesn't
      need to be put. There is no problem, however, when depth is 3, it doesn't put
      the pages correctly where pages[0] is valid and pages[1] is invalid.
      In this case, depth is set to 2 (ref to statemnt depth = i + 1), and then
      'goto fail'.
      In label 'fail', for (i = depth - 3; i >= 0; i--) cannot meet the condition
      because i = -1, so pages[0] cann't be put.

    2) An err happened in the second 'for' loop
      Now we've got pages[0] with depth = 2, or we've got pages[0] and pages[1]
      with depth = 3. When an err is detected, we need 'goto fail' to put such
      the pages.
      When depth is 2, in label 'fail', for (i = depth - 3; i >= 0; i--) cann't
      meet the condition because i = -1, so pages[0] cann't be put.
      When depth is 3, in label 'fail', for (i = depth - 3; i >= 0; i--) can
      only put pages[0], pages[1] also cann't be put.

    Note that 'depth' has been changed before first 'goto fail' (ref to statemnt
    depth = i + 1), so passing this modified 'depth' to the tracepoint,
    trace_f2fs_truncate_partial_nodes, is also incorrect.

    Signed-off-by: Shifei Ge <shifei10.ge@samsung.com>
    [Jaegeuk Kim: modify the description and fix one bug]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: avoid to left uninitialized data in page when read inline data

    Change log from v1:
     o reduce unneeded memset in __f2fs_convert_inline_data

    >From 58796be2bd2becbe8d52305210fb2a64e7dd80b6 Mon Sep 17 00:00:00 2001
    From: Chao Yu <chao2.yu@samsung.com>
    Date: Mon, 30 Dec 2013 09:21:33 +0800
    Subject: [PATCH] f2fs: avoid to left uninitialized data in page when read
     inline data

    We left uninitialized data in the tail of page when we read an inline data
    page. So let's initialize left part of the page excluding inline data region.

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: avoid to read inline data except first page

    Here is a case which could read inline page data not from first page.

    1. write inline data
    2. lseek to offset 4096
    3. read 4096 bytes from offset 4096
    	(read_inline_data read inline data page to non-first page,
    	And previously VFS has add this page to page cache)
    4. ftruncate offset 8192
    5. read 4096 bytes from offset 4096
    	(we meet this updated page with inline data in cache)

    So we should leave this page with inited data and uptodate flag
    for this case.

    Change log from v1:
     o fix a deadlock bug

    Signed-off-by: Chao Yu <chao2.yu@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: improve write performance under frequent fsync calls

    When considering a bunch of data writes with very frequent fsync calls, we
    are able to think the following performance regression.

    N: Node IO, D: Data IO, IO scheduler: cfq

    Issue    pending IOs
    	 D1 D2 D3 D4
     D1         D2 D3 D4 N1
     D2            D3 D4 N1 N2
     N1            D3 D4 N2 D1
     --> N1 can be selected by cfq becase of the same priority of N and D.
         Then D3 and D4 would be delayed, resuling in performance degradation.

    So, when processing the fsync call, it'd better give higher priority to data IOs
    than node IOs by assigning WRITE and WRITE_SYNC respectively.
    This patch improves the random wirte performance with frequent fsync calls by up
    to 10%.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add a sysfs entry to control max_victim_search

    Previously during SSR and GC, the maximum number of retrials to find a victim
    segment was hard-coded by MAX_VICTIM_SEARCH, 4096 by default.

    This number makes an effect on IO locality, when SSR mode is activated, which
    results in performance fluctuation on some low-end devices.

    If max_victim_search = 4, the victim will be searched like below.
    ("D" represents a dirty segment, and "*" indicates a selected victim segment.)

     D1 D2 D3 D4 D5 D6 D7 D8 D9
    [   *       ]
          [   *    ]
                [         * ]
    	                [ ....]

    This patch adds a sysfs entry to control the number dynamically through:
      /sys/fs/f2fs/$dev/max_victim_search

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: remove the needless parameter of f2fs_wait_on_page_writeback

    "boo sync" parameter is never referenced in f2fs_wait_on_page_writeback.
    We should remove this parameter.

    Signed-off-by: Yuan Zhong <yuan.mark.zhong@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: move grabing orphan pages out of protection region

    Move grabing orphan block page out of protection region, and grab all
    the orphan block pages ahead.

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Reviewed-by: Chao Yu <chao2.yu@samsung.com>
    [Jaegeuk Kim: remove unnecessary code pointed by Chao Yu]
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: move alloc new orphan node out of lock protection region

    Move alloc new orphan node out of lock protection region.

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: use spinlock rather than mutex for better speed

    With the 2 previous changes, all the long time operations are moved out
    of the protection region, so here we can use spinlock rather than mutex
    (orphan_inode_mutex) for lower overhead.

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add delimiter to seperate name and value in debug phrase

    Support for f2fs-tools/tools/f2stat to monitor
    /sys/kernel/debug/f2fs/status

    Signed-off-by: Changman Lee <cm224.lee@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: avoid f2fs_balance_fs call during pageout

    This patch should resolve the following bug.

    =========================================================
    [ INFO: possible irq lock inversion dependency detected ]
    3.13.0-rc5.f2fs+ #6 Not tainted
    ---------------------------------------------------------
    kswapd0/41 just changed the state of lock:
     (&sbi->gc_mutex){+.+.-.}, at: [<ffffffffa030503e>] f2fs_balance_fs+0xae/0xd0 [f2fs]
    but this lock took another, RECLAIM_FS-READ-unsafe lock in the past:
     (&sbi->cp_rwsem){++++.?}

    and interrupts could create inverse lock ordering between them.

    other info that might help us debug this:
    Chain exists of:
      &sbi->gc_mutex --> &sbi->cp_mutex --> &sbi->cp_rwsem

     Possible interrupt unsafe locking scenario:

           CPU0                    CPU1
           ----                    ----
      lock(&sbi->cp_rwsem);
                                   local_irq_disable();
                                   lock(&sbi->gc_mutex);
                                   lock(&sbi->cp_mutex);
      <Interrupt>
        lock(&sbi->gc_mutex);

     *** DEADLOCK ***

    This bug is due to the f2fs_balance_fs call in f2fs_write_data_page.
    If f2fs_write_data_page is triggered by wbc->for_reclaim via kswapd, it should
    not call f2fs_balance_fs which tries to get a mutex grabbed by original syscall
    flow.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: missing REQ_META and REQ_PRIO when sync_meta_pages(META_FLUSH)

    Doing sync_meta_pages with META_FLUSH when checkpoint, we overide rw
    using WRITE_FLUSH_FUA. At this time, we also should set
    REQ_META|REQ_PRIO.

    Signed-off-by: Changman Lee <cm224.lee@samsung.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: clean checkpatch warnings

    Fixed a variety of trivial checkpatch warnings.  The only delta should
    be some minor formatting on log strings that were split / too long.

    Signed-off-by: Chris Fries <cfries@motorola.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: call mark_inode_dirty to flush dirty pages

    If a dentry page is updated, we should call mark_inode_dirty to add the inode
    into the dirty list, so that its dentry pages are flushed to the disk.
    Otherwise, the inode can be evicted without flush.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: move a branch for code redability

    This patch moves a function in f2fs_delete_entry for code readability.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: add help function META_MAPPING

    Introduce help function META_MAPPING() to get the cache meta blocks'
    address space.

    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: remove the orphan block page array

    As the orphan_blocks may be max to 504, so it is not security
    and rigorous to store such a large array in the kernel stack
    as Dan Carpenter said.
    In fact, grab_meta_page has locked the page in the page cache,
    and we can use find_get_page() to fetch the page safely in the
    downstream, so we can remove the page array directly.

    Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
    Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: introduce NODE_MAPPING for code consistency

    This patch adds NODE_MAPPING which is similar as META_MAPPING introduced by
    Gu Zheng.

    Cc: Gu Zheng <guz.fnst@cn.fujitsu.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    f2fs: drop obsolete node page when it is truncated

    If a node page is trucated, we'd better drop the page in the node_inode's page
    cache for better memory footprint.

    Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

    Change-Id: I1b7c3378b7f7adb13477376164e91ab080b50d8b

commit bdbe8eee6cd255f86ca24691f1bc76bca563aff9
Author: Evan McClain <aeroevan@gmail.com>
Date:   Thu Mar 20 09:12:16 2014 -0400

    F2FS: Backport to 3.4

    Based off of patches here:
    nowcomputing/f2fs-backports#1

    Change-Id: I2be6d8abf4e3e4c6b9e8d635700930af432fe37a

commit dc7489a69d8cda568b465c5be7f24af71f6030e6
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Thu Dec 20 13:54:51 2012 -0800

    f2fs: Pull in from upstream 3.13 kernel

    Merge tag 'for-3.8-merge' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

    Pull new F2FS filesystem from Jaegeuk Kim:
     "Introduce a new file system, Flash-Friendly File System (F2FS), to
      Linux 3.8.

      Highlights:
       - Add initial f2fs source codes
       - Fix an endian conversion bug
       - Fix build failures on random configs
       - Fix the power-off-recovery routine
       - Minor cleanup, coding style, and typos patches"

    From the Kconfig help text:

      F2FS is based on Log-structured File System (LFS), which supports
      versatile "flash-friendly" features. The design has been focused on
      addressing the fundamental issues in LFS, which are snowball effect
      of wandering tree and high cleaning overhead.

      Since flash-based storages show different characteristics according to
      the internal geometry or flash memory management schemes aka FTL, F2FS
      and tools support various parameters not only for configuring on-disk
      layout, but also for selecting allocation and cleaning algorithms.

    and there's an article by Neil Brown about it on lwn.net:

      http://lwn.net/Articles/518988/

    * tag 'for-3.8-merge' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (36 commits)
      f2fs: fix tracking parent inode number
      f2fs: cleanup the f2fs_bio_alloc routine
      f2fs: introduce accessor to retrieve number of dentry slots
      f2fs: remove redundant call to f2fs_put_page in delete entry
      f2fs: make use of GFP_F2FS_ZERO for setting gfp_mask
      f2fs: rewrite f2fs_bio_alloc to make it simpler
      f2fs: fix a typo in f2fs documentation
      f2fs: remove unused variable
      f2fs: move error condition for mkdir at proper place
      f2fs: remove unneeded initialization
      f2fs: check read only condition before beginning write out
      f2fs: remove unneeded memset from init_once
      f2fs: show error in case of invalid mount arguments
      f2fs: fix the compiler warning for uninitialized use of variable
      f2fs: resolve build failures
      f2fs: adjust kernel coding style
      f2fs: fix endian conversion bugs reported by sparse
      f2fs: remove unneeded version.h header file from f2fs.h
      f2fs: update the f2fs document
      f2fs: update Kconfig and Makefile
      ...

    Conflicts:
    	include/uapi/linux/magic.h

    Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

    Pull f2fs bug fixes from Jaegeuk Kim:
     "This patch-set includes two major bug fixes:
       - incorrect IUsed provided by *df -i*, and
       - lookup failure of parent inodes in corner cases.

      [Other Bug Fixes]
       - Fix error handling routines
       - Trigger recovery process correctly
       - Resolve build failures due to missing header files

      [Etc]
       - Add a MAINTAINERS entry for f2fs
       - Fix and clean up variables, functions, and equations
       - Avoid warnings during compilation"

    * tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs:
      f2fs: unify string length declarations and usage
      f2fs: clean up unused variables and return values
      f2fs: clean up the start_bidx_of_node function
      f2fs: remove unneeded variable from f2fs_sync_fs
      f2fs: fix fsync_inode list addition logic and avoid invalid access to memory
      f2fs: remove unneeded initialization of nr_dirty in dirty_seglist_info
      f2fs: handle error from f2fs_iget_nowait
      f2fs: fix equation of has_not_enough_free_secs()
      f2fs: add MAINTAINERS entry
      f2fs: return a default value for non-void function
      f2fs: invalidate the node page if allocation is failed
      f2fs: add missing #include <linux/prefetch.h>
      f2fs: do f2fs_balance_fs in front of dir operations
      f2fs: should recover orphan and fsync data
      f2fs: fix handling errors got by f2fs_write_inode
      f2fs: fix up f2fs_get_parent issue to retrieve correct parent inode number
      f2fs: fix wrong calculation on f_files in statfs
      f2fs: remove set_page_dirty for atomic f2fs_end_io_write

    Merge tag 'f2fs-for-3.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

    Pull f2fs fixes from Jaegeuk Kim:
     o Support swap file and link generic_file_remap_pages
     o Enhance the bio streaming flow and free section control
     o Major bug fix on recovery routine
     o Minor bug/warning fixes and code cleanups

    * tag 'f2fs-for-3.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (22 commits)
      f2fs: use _safe() version of list_for_each
      f2fs: add comments of start_bidx_of_node
      f2fs: avoid issuing small bios due to several dirty node pages
      f2fs: support swapfile
      f2fs: add remap_pages as generic_file_remap_pages
      f2fs: add __init to functions in init_f2fs_fs
      f2fs: fix the debugfs entry creation path
      f2fs: add global mutex_lock to protect f2fs_stat_list
      f2fs: remove the blk_plug usage in f2fs_write_data_pages
      f2fs: avoid redundant time update for parent directory in f2fs_delete_entry
      f2fs: remove redundant call to set_blocksize in f2fs_fill_super
      f2fs: move f2fs_balance_fs to punch_hole
      f2fs: add f2fs_balance_fs in several interfaces
      f2fs: revisit the f2fs_gc flow
      f2fs: check return value during recovery
      f2fs: avoid null dereference in f2fs_acl_from_disk
      f2fs: initialize newly allocated dnode structure
      f2fs: update f2fs partition info about SIT/NAT layout
      f2fs: update f2fs document to reflect SIT/NAT layout correctly
      f2fs: remove unneeded INIT_LIST_HEAD at few places
      ...

    Merge tag 'f2fs-for-3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

    Pull f2fs update from Jaegeuk Kim:
     "[Major bug fixes]
       o Store device file information correctly
       o Fix -EIO handling with respect to power-off-recovery
       o Allocate blocks with global locks
       o Fix wrong calculation of the SSR cost

      [Cleanups]
       o Get rid of fake on-stack dentries

      [Enhancement]
       o Support (un)freeze_fs
       o Enhance the f2fs_gc flow
       o Support 32-bit binary execution on 64-bit kernel"

    * tag 'f2fs-for-3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (29 commits)
      f2fs: avoid build warning
      f2fs: add compat_ioctl to provide backward compatability
      f2fs: fix calculation of max. gc cost in the SSR case
      f2fs: clarify and enhance the f2fs_gc flow
      f2fs: optimize the return condition for has_not_enough_free_secs
      f2fs: make an accessor to get sections for particular block type
      f2fs: mark gc_thread as NULL when thread creation is failed
      f2fs: name gc task as per the block device
      f2fs: remove unnecessary gc option check and balance_fs
      f2fs: remove repeated F2FS_SET_SB_DIRT call
      f2fs: when check superblock failed, try to check another superblock
      f2fs: use F2FS_BLKSIZE to judge bloksize and page_cache_size
      f2fs: add device name in debugfs
      f2fs: stop repeated checking if cp is needed
      f2fs: avoid balanc_fs during evict_inode
      f2fs: remove the use of page_cache_release
      f2fs: fix typo mistake for data_version description
      f2fs: reorganize code for ra_node_page
      f2fs: avoid redundant call to has_not_enough_free_secs in f2fs_gc
      f2fs: add un/freeze_fs into super_operations
      ...

    Merge tag 'f2fs-for-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

    Pull f2fs updates from Jaegeuk Kim:
     "This patch-set includes the following major enhancement patches.
       - introduce a new gloabl lock scheme
       - add tracepoints on several major functions
       - fix the overall cleaning process focused on victim selection
       - apply the block plugging to merge IOs as much as possible
       - enhance management of free nids and its list
       - enhance the readahead mode for node pages
       - address several cretical deadlock conditions
       - reduce lock_page calls

      The other minor bug fixes and enhancements are as follows.
       - calculation mistakes: overflow
       - bio types: READ, READA, and READ_SYNC
       - fix the recovery flow, data races, and null pointer errors"

    * tag 'f2fs-for-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (68 commits)
      f2fs: cover free_nid management with spin_lock
      f2fs: optimize scan_nat_page()
      f2fs: code cleanup for scan_nat_page() and build_free_nids()
      f2fs: bugfix for alloc_nid_failed()
      f2fs: recover when journal contains deleted files
      f2fs: continue to mount after failing recovery
      f2fs: avoid deadlock during evict after f2fs_gc
      f2fs: modify the number of issued pages to merge IOs
      f2fs: remove useless #include <linux/proc_fs.h> as we're now using sysfs as debug entry.
      f2fs: fix inconsistent using of NM_WOUT_THRESHOLD
      f2fs: check truncation of mapping after lock_page
      f2fs: enhance alloc_nid and build_free_nids flows
      f2fs: add a tracepoint on f2fs_new_inode
      f2fs: check nid == 0 in add_free_nid
      f2fs: add REQ_META about metadata requests for submit
      f2fs: give a chance to merge IOs by IO scheduler
      f2fs: avoid frequent background GC
      f2fs: add tracepoints to debug checkpoint request
      f2fs: add tracepoints for write page operations
      f2fs: add tracepoints to debug the block allocation
      ...

    Merge tag 'for-f2fs-3.11' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

    Pull f2fs updates from Jaegeuk Kim:
     "This patch-set includes the following major enhancement patches:
       - remount_fs callback function
       - restore parent inode number to enhance the fsync performance
       - xattr security labels
       - reduce the number of redundant lock/unlock data pages
       - avoid frequent write_inode calls

      The other minor bug fixes are as follows.
       - endian conversion bugs
       - various bugs in the roll-forward recovery routine"

    * tag 'for-f2fs-3.11' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (56 commits)
      f2fs: fix to recover i_size from roll-forward
      f2fs: remove the unused argument "sbi" of func destroy_fsync_dnodes()
      f2fs: remove reusing any prefree segments
      f2fs: code cleanup and simplify in func {find/add}_gc_inode
      f2fs: optimize the init_dirty_segmap function
      f2fs: fix an endian conversion bug detected by sparse
      f2fs: fix crc endian conversion
      f2fs: add remount_fs callback support
      f2fs: recover wrong pino after checkpoint during fsync
      f2fs: optimize do_write_data_page()
      f2fs: make locate_dirty_segment() as static
      f2fs: remove unnecessary parameter "offset" from __add_sum_entry()
      f2fs: avoid freqeunt write_inode calls
      f2fs: optimise the truncate_data_blocks_range() range
      f2fs: use the F2FS specific flags in f2fs_ioctl()
      f2fs: sync dir->i_size with its block allocation
      f2fs: fix i_blocks translation on various types of files
      f2fs: set sb->s_fs_info before calling parse_options()
      f2fs: support xattr security labels
      f2fs: fix iget/iput of dir during recovery
      ...

    Merge tag 'for-f2fs-3.12' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

    Pull f2fs updates from Jaegeuk Kim:
     "This patch-set includes the following major enhancement patches:
       - support inline xattrs
       - add sysfs support to control GCs explicitly
       - add proc entry to show the current segment usage information
       - improve the GC/SSR performance

      The other bug fixes are as follows:
       - avoid the overflow on status calculation
       - fix some error handling routines
       - fix inconsistent xattr states after power-off-recovery
       - fix incorrect xattr node offset definition
       - fix deadlock condition in fsync
       - fix the fdatasync routine for power-off-recovery"

    * tag 'for-f2fs-3.12' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (40 commits)
      f2fs: optimize gc for better performance
      f2fs: merge more bios of node block writes
      f2fs: avoid an overflow during utilization calculation
      f2fs: trigger GC when there are prefree segments
      f2fs: use strncasecmp() simplify the string comparison
      f2fs: fix omitting to update inode page
      f2fs: support the inline xattrs
      f2fs: add the truncate_xattr_node function
      f2fs: introduce __find_xattr for readability
      f2fs: reserve the xattr space dynamically
      f2fs: add flags for inline xattrs
      f2fs: fix error return code in init_f2fs_fs()
      f2fs: fix wrong BUG_ON condition
      f2fs: fix memory leak when init f2fs filesystem fail
      f2fs: fix a compound statement label error
      f2fs: avoid writing inode redundantly when creating a file
      f2fs: alloc_page() doesn't return an ERR_PTR
      f2fs: should cover i_xattr_nid with its xattr node page lock
      f2fs: check the free space first in new_node_page
      f2fs: clean up the needless end 'return' of void function
      ...

    Merge tag 'for-f2fs-3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

    Pull f2fs updates from Jaegeuk Kim:
     "This patch-set includes the following major enhancement patches.
       - add a sysfs to control reclaiming free segments
       - enhance the f2fs global lock procedures
       - enhance the victim selection flow
       - wait for selected node blocks during fsync
       - add some tracepoints
       - add a config to remove abundant BUG_ONs

      The other bug fixes are as follows.
       - fix deadlock on acl operations
       - fix some bugs with respect to orphan inodes

      And, there are a bunch of cleanups"

    * tag 'for-f2fs-3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (42 commits)
      f2fs: issue more large discard command
      f2fs: fix memory leak after kobject init failed in fill_super
      f2fs: cleanup waiting routine for writeback pages in cp
      f2fs: avoid to use a NULL point in destroy_segment_manager
      f2fs: remove unnecessary TestClearPageError when wait pages writeback
      f2fs: update f2fs document
      f2fs: avoid to wait all the node blocks during fsync
      f2fs: check all ones or zeros bitmap with bitops for better mount performance
      f2fs: change the method of calculating the number summary blocks
      f2fs: fix calculating incorrect free size when update xattr in __f2fs_setxattr
      f2fs: add an option to avoid unnecessary BUG_ONs
      f2fs: introduce CONFIG_F2FS_CHECK_FS for BUG_ON control
      f2fs: fix a deadlock during init_acl procedure
      f2fs: clean up acl flow for better readability
      f2fs: remove unnecessary segment bitmap updates
      f2fs: add tracepoint for vm_page_mkwrite
      f2fs: add tracepoint for set_page_dirty
      f2fs: remove redundant set_page_dirty from write_compacted_summaries
      f2fs: add reclaiming control by sysfs
      f2fs: introduce f2fs_balance_fs_bg for some background jobs
      ...

    Change-Id: Ied5488471d49d64ce6abb4be19237c4e90829ff6
Version 5.8.3
Merge branch 'testing' into 5.x