diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2015-08-16 23:04:50 +0300 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2015-08-20 19:00:14 +0300 |
commit | 24928634f81b1592e83b37dcd89ed45c28f12feb (patch) | |
tree | 41ae5bc8bbb6b21f79bed92a59b5bd8cec99242d /fs/f2fs | |
parent | a21c20f0c812925085204fced932ac95f2a76bf0 (diff) | |
download | linux-24928634f81b1592e83b37dcd89ed45c28f12feb.tar.xz |
f2fs: check the node block address of newly allocated nid
This patch adds a routine which checks the block address of newly allocated nid.
If an nid has already allocated by other thread due to subtle data races, it
will result in filesystem corruption.
So, it needs to check whether its block address was already allocated or not
in prior to nid allocation as the last chance.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs')
-rw-r--r-- | fs/f2fs/node.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 3cc32b8f8204..6bef5a2788b4 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1573,6 +1573,8 @@ retry: /* We should not use stale free nids created by build_free_nids */ if (nm_i->fcnt && !on_build_free_nids(nm_i)) { + struct node_info ni; + f2fs_bug_on(sbi, list_empty(&nm_i->free_nid_list)); list_for_each_entry(i, &nm_i->free_nid_list, list) if (i->state == NID_NEW) @@ -1583,6 +1585,13 @@ retry: i->state = NID_ALLOC; nm_i->fcnt--; spin_unlock(&nm_i->free_nid_list_lock); + + /* check nid is allocated already */ + get_node_info(sbi, *nid, &ni); + if (ni.blk_addr != NULL_ADDR) { + alloc_nid_done(sbi, *nid); + goto retry; + } return true; } spin_unlock(&nm_i->free_nid_list_lock); |