f2fs: fix to account total free nid correctly
authorChao Yu <yuchao0@huawei.com>
Thu, 17 Nov 2016 12:53:11 +0000 (20:53 +0800)
committerJaegeuk Kim <jaegeuk@google.com>
Mon, 25 Sep 2017 22:36:56 +0000 (15:36 -0700)
commit031017c6f9922c9c7b7819e876531de3f7ecb065
tree4c286f5f16eaeb050630d2201a56911523114e63
parentbeaab6afb4c86fd7daa47577220d597cdc183a46
f2fs: fix to account total free nid correctly

commit 04d47e673863c637a2b44ad34a558aeb5d0a727e upstream.

Thread A Thread B Thread C
- f2fs_create
 - f2fs_new_inode
  - f2fs_lock_op
   - alloc_nid
    alloc last nid
  - f2fs_unlock_op
- f2fs_create
 - f2fs_new_inode
  - f2fs_lock_op
   - alloc_nid
    as node count still not
    be increased, we will
    loop in alloc_nid
- f2fs_write_node_pages
 - f2fs_balance_fs_bg
  - f2fs_sync_fs
   - write_checkpoint
    - block_operations
     - f2fs_lock_all
 - f2fs_lock_op

While creating new inode, we do not allocate and account nid atomically,
so that when there is almost no free nids left, we may encounter deadloop
like above stack.

In order to avoid that, reuse nm_i::available_nids for accounting free nids
and make nid allocation and counting being atomical during node creation.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/node.c