Squashed commit of the following:
from Chao Yu <chao2.yu@samsung.com>

commit aec32af723c2aae9aa1d39f09b323bb13843a145
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Sat Aug 30 09:52:34 2014 +0800

    f2fs: reposition unlock_new_inode to prevent accessing invalid inode

    As the race condition on the inode cache, following scenario can appear:
    [Thread a]				[Thread b]
    					->f2fs_mkdir
    					  ->f2fs_add_link
    					    ->__f2fs_add_link
    					      ->init_inode_metadata failed here
    ->gc_thread_func
      ->f2fs_gc
        ->do_garbage_collect
          ->gc_data_segment
            ->f2fs_iget
              ->iget_locked
                ->wait_on_inode
    					  ->unlock_new_inode
            ->move_data_page
    					  ->make_bad_inode
    					  ->iput

    When we fail in create/symlink/mkdir/mknod/tmpfile, the new allocated inode
    should be set as bad to avoid being accessed by other thread. But in above
    scenario, it allows f2fs to access the invalid inode before this inode was set
    as bad.
    This patch fix the potential problem, and this issue was found by code review.

    change log from v1:
     o Add condition judgment in gc_data_segment() suggested by Changman Lee.
     o use iget_failed to simplify code.

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

    Conflicts:
    	fs/f2fs/namei.c

    Change-Id: Ie9184ec9076dcad810f22fb5b7ab98e3fcb19b4d

commit 6cc4b97a7e80448d7bd6ede4ba5282f48ea0d187
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Fri Aug 29 00:26:50 2014 -0700

    f2fs: fix wrong casting for dentry name

    The dentry name type is unsigned char *.
    If we don't match this type, some character codes can be changed by signed bit.

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

commit 4bd38f94803ac27beb99fb9253778aec485606d5
Author: Dan Carpenter <dan.carpenter@oracle.com>
Date:   Thu Aug 28 16:13:21 2014 +0300

    f2fs: simplify by using a literal

    We can make the code a bit simpler because we know that "!retry" is
    zero.

    Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit a7d98622fddac96809e6a03852e5bf1cb61f4692
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Mon Aug 25 14:45:59 2014 -0700

    f2fs: truncate stale block for inline_data

    This verifies to truncate any allocated blocks, offset[0], by inline_data.
    Not figured out, but for making sure.

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

commit 21852777c25d830ada31a314e54b9ad24dc5190d
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Fri Aug 22 16:17:38 2014 +0800

    f2fs: use macro for code readability

    This patch introduces DEF_NIDS_PER_INODE/GET_ORPHAN_BLOCKS/F2FS_CP_PACKS macro
    instead of numbers in code for readability.

    change log from v1:
     o fix typo pointed out by Jaegeuk Kim.

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

commit c6521bdaa420d945373d3381c5b3c04773b9c0d0
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Wed Aug 20 18:37:35 2014 +0800

    f2fs: introduce need_do_checkpoint for readability

    This patch introduce need_do_checkpoint() to include numerous judgment condition
    for readability.

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

commit db4001782fa39e5203513d1edc3bb1eca20a8eb2
Author: Chao Yu <chao2.yu@samsung.com>
Date:   Wed Aug 20 18:36:46 2014 +0800

    f2fs: fix incorrect calculation with total/free inode num

    Theoretically, our total inodes number is the same as total node number, but
    there are three node ids are reserved in f2fs, they are 0, 1 (node nid), and 2
    (meta nid), and they should never be used by user, so our total/free inode
    number calculated in ->statfs is wrong.

    This patch indroduces F2FS_RESERVED_NODE_NUM and then fixes this issue by
    recalculating total/free inode number with the macro.

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

commit 79f7d91f3e369052e73c8b4869ef167c044144dd
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Mon Aug 18 14:41:11 2014 -0700

    f2fs: skip if inline_data was converted already

    This patch checks inline_data one more time under the inode page lock whether
    its inline_data is converted or not.

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

commit ea673e2be18bf07c99fc5baeedd36cc9bed2a327
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Fri Aug 15 09:56:46 2014 -0700

    f2fs: remove rewrite_node_page

    I think we need to let the dirty node pages remain in the page cache instead
    of rewriting them in their places.
    So, after done with successful recovery, write_checkpoint will flush all of them
    through the normal write path.
    Through this, we can avoid potential error cases in terms of block allocation.

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

commit b07c23faf980367b4c75848aa9ca35a0b2098022
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Thu Aug 14 16:32:54 2014 -0700

    f2fs: avoid double lock in truncate_blocks

    The init_inode_metadata calls truncate_blocks when error is occurred.
    The callers holds f2fs_lock_op, so we should not call it again in
    truncate_blocks.

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

    Conflicts:
    	fs/f2fs/data.c

    Change-Id: I8f9947c79c6f801f91dad23327f89519f58e1861

commit f2198b31cc0f55d899a740bb90bdea6ac64959f4
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Wed Aug 13 10:45:41 2014 -0700

    f2fs: add WARN_ON in f2fs_bug_on

    This patch adds WARN_ON when f2fs_bug_on is disable to see kernel messages.

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

commit 3a5a42a74cfb05778049ac50925831c78b8fdff4
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Mon Aug 11 18:37:46 2014 -0700

    f2fs: handle EIO not to break fs consistency

    There are two rules when EIO is occurred.
    1. don't write any checkpoint data to preserve the previous checkpoint
    2. don't lose the cached dentry/node/meta pages

    So, at first, this patch adds set_page_dirty in f2fs_write_end_io's failure.
    Then, writing checkpoint/dentry/node blocks is not allowed.

    Note that, for the data pages, we can't just throw away by redirtying them.
    Otherwise, kworker can fall into infinite loop to flush them.
    (Ref. xfstests/019)

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

commit 39a93844dcf17a9be2ba64ca0353c9a0ae44b3ef
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Mon Aug 11 18:37:46 2014 -0700

    f2fs: check s_dirty under cp_mutex

    It needs to check s_dirty under cp_mutex, since s_dirty is reset under that
    mutex.
    And previous condition was not correct, since we can omit doing checkpoint
    when checkpoint was done followed by all the node pages were written back.

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

commit 9549bd2221be420cfe89d2802741a998a9afd57c
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Mon Aug 11 18:18:36 2014 -0700

    f2fs: unlock_page when node page is redirtied out

    This patch fixes missing unlock_page when a node page is redirtied out.

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

commit c3d47e83433e873e8fc817a47f27042a62ea75a5
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Mon Aug 11 16:49:25 2014 -0700

    f2fs: introduce f2fs_cp_error for readability

    This patch adds f2fs_cp_error for readability.

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

commit 358968f87c68dac871336fca53b432273be77ff9
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Fri Aug 8 15:37:41 2014 -0700

    f2fs: give a chance to mount again when encountering errors

    This patch gives another chance to try mount process when we encounter an error.
    This makes an effect on the roll-forward recovery failures as well.

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

commit 4615b091fb6db273e8d192c8ea8c6e26f62b6ab4
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Tue Aug 19 09:48:22 2014 -0700

    f2fs: trigger release_dirty_inode in f2fs_put_super

    The generic_shutdown_super calls sync_filesystem, evict_inode, and then
    f2fs_put_super. In f2fs_evict_inode, we remain some dirty inode information
    so we should release them at f2fs_put_super.

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

commit 49459fdf24c33fb6fe3b349c73b3f8b80cf6eb1e
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Tue Aug 19 09:13:01 2014 -0700

    f2fs: don't skip checkpoint if there is no dirty node pages

    This is the errorneous scenario.
    1. write data
    2. do checkpoint
    3. produce some dirty node pages by the gc thread
    4. write back dirty node pages
    5. f2fs_put_super will skip the checkpoint, since dirty count for node pages is
      zero.

    This patch removes such the wrong condition check.

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

commit 69ffb8f9675cb2785497900eb53d036f1da01684
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Fri Aug 8 10:18:43 2014 -0700

    f2fs: avoid bug_on when error is occurred

    During the recovery, if an error like EIO or ENOMEM, f2fs_bug_on should skip.

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

commit 2152fe8acf4fe2666e7bfecd1d4074eb3fe0ae7c
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Thu Aug 7 23:49:17 2014 -0700

    f2fs: fix to recover inline_xattr/data and blocks

    This patch fixes not to skip xattr recovery and inline xattr/data recovery
    order.

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

commit d48c98fbbfd568f2367846e046d6bbb0dfccfc2a
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Thu Aug 7 23:45:42 2014 -0700

    f2fs: should clear the inline_xattr flag

    During the recovery, we should clear the inline_xattr flag if its xattr node
    block is recovered.

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

commit ad487100ff9d80f2146854bfb5dfa58ad2b9fb02
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Thu Aug 7 17:06:18 2014 -0700

    f2fs: clear FI_INC_LINK during the recovery

    If an inode are fsynced multiple times with fsync & dent marks, this inode will
    set FI_INC_LINK at find_fsync_dnodes during the recovery.
    But, in recover_inode, recover_dentry doesn't clear that flag when multiple hits
    were occurred.

    So this patch removes the flag for the further consistency.

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

commit df49c8b627831594b3170a3277df50b8dcca2d82
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Thu Aug 7 17:04:24 2014 -0700

    f2fs: fix the initial inode page for recovery

    If a new inode page is needed for recover_dentry, we should assing i_inline
    as zero.

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

commit 7ae3fa7438b6fe4a6f710b15cc8396311c1c7bd7
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Thu Aug 7 16:57:17 2014 -0700

    f2fs: make clear on test condition and return types

    This patch adds a parentheses to make clear for condition check.
    And also it changes the return type for better meanings.

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

commit e70dce37bd16637a17550281259e7684e76a2e69
Author: Jaegeuk Kim <jaegeuk@kernel.org>
Date:   Thu Aug 7 16:32:25 2014 -0700

    f2fs: should convert inline_data during the mkwrite

    If mkwrite is called to an inode having inline_data, it can overwrite the data
    index space as NEW_ADDR. (e.g., the first 4 bytes are coincidently zero)

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

commit 6ed3713bc133c7d1d51ce6d76b7c030bd97e8f80
Author: arter97 <qkrwngud825@gmail.com>
Date:   Wed Aug 6 23:22:50 2014 +0900

    f2fs: fix typo

    Fix typo and some grammatical errors.

    The words "filesystem" and "readahead" are being used without the space treewide.

    Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
    Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

commit df58158a1f48913ef9e7f60a4c34e831095e247f
Author: Dan Pasanen <dan.pasanen@gmail.com>
Date:   Sun Sep 7 03:01:33 2014 -0500

    Fix warnings for gcc-4.9

    Change-Id: I07eb9f9d24e9524fbe28ffd563f5e9d079da49df

commit 4821eda5f868153a0282e278c7085f5e3b23222f
Author: Vineeta Srivastava <vsrivastava@google.com>
Date:   Wed Dec 18 14:37:35 2013 -0800

    Fix sizeof-pointer-memaccess warning with gcc 4.8

    This patch fixes wrong memcpy size when copying ltk value to
    HCI_OP_LE_LTK_REPLY command.

Conflicts:
	fs/f2fs/node.c

Change-Id: Ief1d5942d4bb26ac275d0cc7344c86f7b4319e5d